Problem with foreach loop with GameObject array

I have a few enemies in my scene that I want to be active one at a time. As i destroy an enemy, the next one will become active. Here’s what I’m working with:

EnemyAI.cs

    public static bool isActive = true;

	void Update()
	{
		if(isActive == false)
		{
			GetComponent<EnemyAI>().enabled = false;
		}

	}

In the script above, I have the isActive bool set to true but I want the script to be disabled if it is set to false, here’s where my problem is:

EnemyBehaviour.cs

public int shipCount = 13;

void Start()
{

	GameObject[] ships = new GameObject[shipCount];
	
	for(int i = 1; i < shipCount; i++)
	{
		ships *= GameObject.FindWithTag ("ship" + i);*

_ foreach(GameObject ship in ships*)_
_
{_
_
EnemyAI.isActive = false;_
_
}_
_
}_
_
}_
I want to find all of my ships with the correct tags and set them to false (except for the first one, that’s why I start the loop at 1)
I used a for loop to find the objects and I wanted to then use a foreach loop to iterate through that list and set each ships (not including the first one) bool isActive to false but it throws me this error:
_
[31406-capture.png*|31406]*
_*
I’m a bit stumped as to how to work around it so if anyone could help me out, I’d appreciate it

public int shipCount = 13;

void Start()
{
     GameObject[] ships = new GameObject[shipCount];
 
    for(int i = 1; i < shipCount; i++)
    {
        ships *= GameObject.FindWithTag ("ship" + i);*

}

foreach(GameObject ship in ships)
{
EnemyAI.isActive = false;
}
}

I think this should work for you…
because for a foreach loop you need a collection of objects…in your case an array ‘ships’ of GameObject type.
Plus … I am not aware of your game logic… if you want 13 ships then use
for(int i = 1; i < shipCount + 1; i++)

//instead of

for(int i = 1; i < shipCount; i++)
because according to your logic the for loop will execute only 12 times…
Hope that helped…
And thanks…for the vote up in advance… :stuck_out_tongue:

This line

    foreach(GameObject ship in ships*)*

Should be this
foreach(GameObject ship in ships)