Destroy one child (of same instance) after another?
Hey, so the way my game works right now is that due to a certain event, a bunch of "Point"-objects spawn, and they instantly attach themselves to a "Target"-object as children.
The Target has a constant timer running down, and every x seconds, it should destroy one of the Points-Children attached to it - only one at a time though! And it doesn't matter which one. Once one is destroyed, the Timer resets, and only when x seconds have passed again, it should destroy another Point-Child - until none are left.
What I thought I could do in Unity is have the Target run through its own list of children, and as soon as it finds one Point-object in its Child-list, it would destroy that and reset the timer. I'm not sure how to do that though, or if it's the best solution, so any help and ideas are appreciated!
Thank you very much!
Haha again I'm not sure which part you need help. It all sounds reasonable to me so far. So I'll just write whatever things that comes to my $$anonymous$$d and hope it doesn't sounds dumb.
Create a List of "Point". Cache all "Point" children on Start().
private List<Point> pointList = new List<Point>();
void Start () {
// Here you cache all "Point"
// You'll need
// https://docs.unity3d.com/ScriptReference/Component.GetComponentsInChildren.html
// https://unity3d.com/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries
}
And the Timer thing just google "Unity Timer".
When time arrives, you need to Destroy() a "Point". You said "it doesn't matter which one" so you'll need to pick a random one from the List. $$anonymous$$aybe you need to generate a random index and use it to pick from List. Then reset the timer.
Finally, you said "due to a certain event"... it depends on how you want to do it. $$anonymous$$aybe you need this or maybe not. But you'll need to move the "Point" cacheing part from Start() to another function, say "OnPointSpawn()". So when that event happens you call OnPointSpawn().