# Is it possible to create new variables by incrementing?

 0 So, I have a wall of 2d bricks, and when you click on any of the bricks, it is destroyed and a 3d brick is instantiated on that spot and flies forward. If you click on the flying 3d brick, it then gets destroyed and a new 2d brick needs to emerge in the spot of the original. `````` tempRedBrick = Instantiate(prefabBrick, transform.position, transform.rotation); static var posBrick: Vector3 = transform.position; static var rotBrick: Quaternion = transform.rotation; `````` Using this code, I get the original position of the 2d brick on the wall, and the new 2d brick is instantiated there. However, it always uses the position of the last 2d brick clicked. I have a static var that increments every time you click on a 2d brick on the wall, I was wondering if there was a way to use this variable in combination with the position and rotation storing variables. This way, the game understands where the 3d brick originally emerged from. e.g. can I start with something like posBrick0 then the next 2d brick that is clicked is posBrick1, then posBrick2, etc. ? more ▼ asked Nov 23 '10 at 01:58 AM Wylie 54 ● 11 ● 12 ● 20 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 I don't entirely understand your problem from the description, but just going on your very last sentence, it sounds like you need to use an Array for this. eg: var bricks = new Array(); function DoBrickStuff() { ``````tempBrick = Instantiate( prefabBrick, .....etc ); bricks.Add(tempBrick); `````` } You'll then find that your "bricks" array contains a reference to each brick created, and you can access them like this: ``````bricks[n].transform.position; `````` Where "n" is a numeric var containing the index number of the item you want from the array. The index is "zero-based" meaning the first item is zero, the second item is 1, etc. more ▼ answered Nov 23 '10 at 08:06 AM duck ♦♦ 41.4k ● 95 ● 152 ● 415 works like a charm! thanks! Nov 27 '10 at 04:22 PM Wylie add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x3569
x356
x111

asked: Nov 23 '10 at 01:58 AM

Seen: 572 times

Last Updated: Nov 23 '10 at 01:58 AM