Hi Steve,
Welcome to our community! ![]()
Should I try and build an array of remaining enemies each time one is killed and then end the game when the array is empty?
Yes, that could be an idea. Alternatively, you could remove a specific enemy from a List. Unlike arrays, Lists are mutable. Look for “C# method overload” if you don’t know this technique yet. It could be helpful.
I thought it would fill an array with only active enemy ships but it doesn’t seem to do that.
Do your enemies have got the “Enemy” tag? And are your enemies active when that line of code gets executed?
I have all my enemy ships in a Hierachy folder called ‘Enemy Ships’ which empties out as each enemy ship is destroyed.
If you have an “Enemy Ships” root object and the children are enemies, you could simply use transform.childCount to see how many enemies are “alive”.
See also:
- Forum User Guides : How to apply code formatting within your post
- Forum User Guides : How to mark a topic as solved