So, I’m getting this weird (at least for a beginner like me) behavior when instanciating and destroying shots on this shoot 'em up sketch I’m trying to develop.
Every Shot prefab has an instance of ShotScript.
I have this inside it’s Start():
Destroy(gameObject, 20);
Sooo… I’m expecting that the gameObject which has this instance of script attached to it to be the one destroyed after 20 seconds, so that the shots are always destroyed from oldest to newest, as in a FIFO behavior. But that’s not what’s happening. Apparently,
every clone is being destroyed, but randomly. Let’s say I have shots 1, 2, and 3, 3 being the oldest. After 20 seconds 1 or 2 gets destroyed instead of 3. To exclude any possibility of memory leaking, I’ve commented the Destroy line and I’ve got some 200 shots instantiated, but none of them was destroyed (as one would expect). So, I’ve ruled this possibility out. Oh, and I should also mention that I had this same problem when trying to destroy via OnTriggerExit2D.
What am I missing here?
P.S: an image illustrating my problem (I didn’t mention, but Player is the shooter, not someone being shot):
http://s12.postimg.org/pxpc696il/weird.png