Find active gameobject inside array.

This should be something pretty simple but Im just not grasping or finding an answer. I have an array of game objects, 31 in total. There is only one of these active at one time and all of them have the Player tag assigned. Right now I was trying

AlliArray[AlliBabyC] = GameObject.FindWithTag("Player");

and later in my code I want to accomplish

AlliArray[AlliBabyC - 1].SetActive(true);
AlliArray[AlliBabyC].SetActive(false);
AlliBabyC--;

Im not sure what Im doing wrong here. Thanks for any help.

Hello.


First, to assign all GameObjects with a Tag in a array, you must use (Objects, with S):

And not (which only returns first object found)


Second, I’m not sure what you want to get. If just want to set unactive the activeone and active the next

for(int i=0; i<AlliArray.length; i++)
{    
  if (AlliArray*.activeInHierarchy)*

{
AlliArray*.SetActive(false);*
if (i != 0) AlliArray[i-1].SetActive(true);
else AlliArray[AlliArray.length-1].SetActive(true);
}
}
----------
If you are learning, do not just copy-paste. Do not continue until 100% understanding what’s happening here.
Bye!

Yes that is pretty much all I am doing. Just moving up and down the array. But the thing is I might be starting on AlliArray[7] during the start of the code, as an example. Im trying to understand this a bit better, so the for loop will look through the array one by one and then the if statement is if found run the code. That correct? Also what is that else statement doing exactly at the end? Thanks for the help!