Answers for "Instantiating grid of objects starting at the bottom left of the viewport"
http://answers.unity.com/questions/1304244/instantiating-grid-of-objects-starting-at-the-bott.html
The latest answers for the question "Instantiating grid of objects starting at the bottom left of the viewport"Answer by Bunny83
http://answers.unity.com/answers/1304432/view.html
Well, if you want to lay them out on the screen you don't want to use the Viewport space. Viewport coordinates goes from 0 to 1. So 0,0 is the bottom left corner and 1,1, is the top right corner of the screen. Those are also square-coordinates while the screen itself is usually a rectangle so even when calculating the right scale you have to deal with the aspect ratio as well.
If each tile is one world unit wide, just place them in worldspace. You can use ViewportToWorldPoint to determine the "first point". Something like that:
Vector3 start = Camera.main.ViewportToWorldPoint(new Vector3(0f, 0f, 0f)) + new Vector3(0.5f, 0.5f, 0f);
for (int i = 0; i < grid.GetLength(0); i++)
{
for (int j = 0; j < grid.GetLength(1); j++)
{
grid[i, j] = Instantiate(tile, start + new Vector3(i, j, 0f), Quaternion.identity);
}
}
I added "0.5" on the x and y axis since it looks like your prefabs origin is in the center. Since you said a tile is 1 unit wide moving it 0.5 will place it right in the lower left corner. Now you just add "whole units" to each axis (since integers are whole numbers it should work out just right). If for some reason your tiles are larger or smaller you just have to multiply "i" and "j" with your scaling factor. If you want a little space between the tiles you can do
+ new Vector3(i*(1f + 0.1f), j*(1f + 0.1f), 0f),
Here the "1f" would be the scale / worldsize of one tile and the "0.1f" would be the space between those tilesThu, 26 Jan 2017 14:13:26 GMTBunny83