- Home /
Question by
imagee · Jul 16, 2014 at 02:39 PM ·
c#gameobjectinstantiatearraylist
What is the best way to instatiate an array of connected GameObjects?
Im trying to create a 2d side scroller with telephone poles placed along a road with a wires connecting between each pole. The poles and wires need to be dynamically created as the camera moves further to the right. I already have a function that creates a wire between two positions.
this is basicly what im trying to do:
update{
if(camera.position.x > last_pole.x)
{
//create pole
new_pole_position = last_pole.x + 20;
new_pole = instantiate(pole, new_pole_position)
//connect wire between new pole and last pole
create_wire(last_pole, new_pole)
}
}
What is the best way to create a collection of GameObjects where I can easily access the the newest and previous created GameObject?
Comment
For performance sake you may want to look into pooling your objects.
When you need them add the to an "acitve" List. Then, return them to the pool after they are out of view.