- Home /
Assign a gameobject in a scene to a varible automatically?
Hi, I am using empty gameobject's positions to instantiate platforms at their position. The only problem is I have around 729 empty gameobjects and I need to link them all to their variable in the script. I do not have time or the persistence to drag 729 gameobjects onto 729 variables. Any idea how I could do this automatically? It does not have to be within the script it self. Thanks in advanced!
It can be done with editor or runtime scripts. If you provide more information, folks on the list can give you a more detailed answer. In particular, can you post the script that needs to have variables initialized, along with a description of how their values are initialized. If you provide a more general description of how the 729 game objects are being used, there may be yet again another approach as well.
Ok... So basically I need to randomly instantiate platforms to create a path. I am doing this in C# by using empty gameobjects to hold transform data. When i want to instantiate a certain number of platform s I will do so by randomly selecting X amount of transforms from the list of empty gameobjects. I am using public Gamobject (platform1); and at start up Platformlist.add(Platform1.transform)
Need anymore info? Thanks!
It's still pretty unclear. What needs to store information? If you just need to collect all the empty game objects into an array, you can tag all the empty game objects and use GameObject.FindWithTag() to find all the transorms. If you need to store information in a script attached to each platform, that is a different solution. So what kind of information do you want to automatically store and where do you want to store it?
Well that answered my question :P I guess using GameObject.FindWithTag() should work! Thanks lol