How can an object add itself to a scripts Array when it's instantiated?

I have a manager script that manages all the enemies in my scene. To do this it has an array called EnemyObject where it manages all the objects at once. How can I have the enemy add itself to the EnemyObject array when its instantiated?

Thanks Stealth

You need to make it a list instead of an array as this makes adding objects much easier, using .Add(). For each of the new enemies to be able to access the list, you need to make it a static variable (E.g. Inside the Manager script, when declaring the list, use public static List< GameObject> = new List ():wink:
You’ll need to add the System.Collections.Generic and System.Linq library headers to use Lists and Add(), respectively.

Then, in order for each new enemy to add itself to the list, you should do the work inside their Start function. Something like EnemyObjects.Add(gameObject);

This is untested but should work. Let me know how you get on.