How to find the "youngest" Game Object?
I create clones of an existing GameObject on my scene. Sometimes I need to remove the one which was instantiated the last. How can I determine which clone is the newest one?
Answer by Oscar-Bear · Apr 24, 2017 at 11:02 AM
You can put the instantiated objects into an Array or List when u instantiating it, so the last one/ "newest" will have the last index in the array. @punkrockchicken
Hey, thank you! I am doing like that: creating a List
public List<GameObject> trails = new List<GameObject>();
then I add a new item to the list
trails.Add (thisTrail);
then I try to destroy the last one:
var item = trails[trails.Count - 1];
Destroy (item);
But gameObject remains on the scene and the List is extended with one empty position. What am I doing wrong?
Your answer
Follow this Question
Related Questions
How Can I assign a gameobject via script? 0 Answers
How can i find a GameObject.transform with a concatenated string 0 Answers
setting a variable to a GameObject that has a certain RGB value??? please help 0 Answers
GameObject.Find throws be a error when trying to find a child. 1 Answer
(Solved) Findout if an object exist in the scene, but dont trow exception 1 Answer