- Home /
Grid layout problem
with this code I am trying to make a grid:
var tex1 : Texture; var tex2 : Texture; var plane : GameObject; var x = 4; var y = 4;
function Start() { var i; var j;
for(i = 0; i < y; i++) for(j = 0; j < x; j++) { plane.renderer.material.SetTexture("MainTex", tex1); Instantiate(plane, Vector3(i, 0, j), transform.rotation); plane.name = "Plane[" + j + "][" + i + "]"; } }
the grid should look like this:
0,0|0,1|0,2|0,3
1,0|1,1|1,2|1,3
2,0|2,1|2,2|2,3
3,0|3,1|3,2|3,3
but instead this is what I get:
2,0|2,1|2,2|2,3
1,0|1,1|1,2|1,3
0,0|0,1|0,2|0,3
3,3|3,0|3,1|3,2
I honestly have no idea. I have tried debugging it with print statements. Any input would be greatly appreciated.
Again, like your other question, your problems are not reproducible on others' systems. Try pasting this into a new project; there's something about your current one that is causing you unnecessary grief.
I have also been running into this problem. I think it has something to do with how x, y, and z are set up in Unity and when you use Instantiate. I'll see if I can come up with something.
Can someone try this code out? Just grab a couple google images and make a cube primitive for the "plane"? The only thing I've figured out is that the actual placement of the planes is correct, but its the plane.name is what is causing trouble.
You (or the OP) might have better luck getting people to try it out if you could provide a Unity package demonstrating the problem. (Then, people can just drop that into a project and observe the behavior themselves.)
Your answer
Follow this Question
Related Questions
Connect the Dot Game Grid for iPad 0 Answers
How can I make irregular grid for strategy game? 1 Answer
How to generate an occupancy grid of the scene? 1 Answer
How do I snap an object to a circular grid 2 Answers
How to check if a grid unit position has a tile from the Tile Palette placed on it? 1 Answer