Activating and Deactivating in order

So I have a list of 10 objects. When those objects are instantiated they are SetActive to false. And when the players moves a certain point along the X axis they start to activate randomly.

How would I go by as to make it so they SetActive(True) one after the other, and when the last one is Active make the first one UnActive.

Okay I got it to SetActive in order by using:

list[count - 2].SetActive(true);

Now how do I do it in reverse?

Starting from the first object to the last.

You could either go thorough the list to check which object is the last active in it or just have a variable that keeps track of the last activated object. Something like this should work…

var list .... 
var node : int = 0;

function activateNext(){
   adjustNode(node);
   node = node == list.size-1? 0 : node+1;
}

function adjustNode(int nr){
   if(list[nr].isActive()){
       list[nr].setActive(false);
   } else {
       list[nr].setActive(true);
   }
}

This should keep going through the list when you call “activateNext” (which isn’t the best name for that function). I didn’t really get if you wanted to deActive the first object at the same time the last one is activated or deActive it after the last one is active but I guess you should get the idea