- Home /
How to destroy the first clone of a UI Image using an array every time I press a button?
Here is a line of code that I used inside the void Update() function to make clones of the UI Image "car".
Image c = Instantiate (car, carPos, transform.rotation, transform.parent) as Image;
How do I store all the clones to an array and destroy the first one, every time I press a button?
If i use..`Destroy(c);` only the clone instantiated at that moment would be destroyed. But I want only the first clone to get destroyed. (each time I press the button)
Please help me fix this. Thanks in advance.
Answer by $$anonymous$$ · Jan 26, 2018 at 06:30 PM
If you are going to be adding and removing things, I suggest that you use a list.
Destroy(MyList[0]);
MyList.Remove(MyList[0]);
This will remove and destroy the first item in a list, if you add something to the list, it's number will be equal to the current last item on the list plus one.
Your answer
Follow this Question
Related Questions
How do you destroy a clone ?c# 1 Answer
Why could I delete my clones onlY in the same order of instantiation? 2 Answers
strange cloning array beviour 1 Answer
finding clones and destroying them doesn't work 0 Answers
Multiple Cars not working 1 Answer