Reputation: 47
I am trying to make a simple 2d platformer endless running game using unity game engine also i am completely new to the unity game engine and c# scripting. Within the game i am using the instantiate for spawning the platforms. I managed to spawn gameobjects to the scene. My question is that how to find the previously spawned objects using c# script. it will be a great help if anyone provided the code. And sorry for my bad language
Upvotes: 0
Views: 746
Reputation: 16277
List<Object> existingOnes = new List<Object>();
var clone = Instantiate(...);
clone.name= "0001";
existingOnes.Add(clone);
var theOne = existingOnes.Where(item
=> item.name.Equals("0001").FirstOrDefault();
Note that "theOne" might no longer exist if you dynamically destroyed it.
If the clone is GameObject, you can also use:
GameObject.Find(...)
to get access to it.
Upvotes: 3