For loops

Im trying to create a custom window editor that puts a object in the viewport then it can skip X number of space on a axis, and I have nearly everything right, I can create the right amount of objects based on an input and the first object does skip but the other ones don’t(i.e If i inputed for 4, the first one does skip X number of spaces, but not 2,3 and 4).

for(int i = 0; i < DupNum; i++) {
            
                            GameObject.CreatePrimitive(PrimitiveType.Cube);


                        for(int t = 0; t < DupNum; t++) {
                            var customPosition = Selection.activeGameObject;
                            customPosition.transform.position = new Vector3(xCords + SkipX, yCords + SkipY, zCords + SkipZ);

                        }
                 }

for some reason the first for loop didnt work for continous skiiping, just the first object.

CreatePrimitive gives you a cube back. You’re not doing anything with that value, so if you expect the cube you make to go somewhere, it won’t. I don’t know what customPosition is, and I assure you the newly-created cube doesn’t know either. :slight_smile:

Assign it to a Gameobject variable, then you can modify its transform.position all you want.

1 Like