Activate objects in array based on value

Hi, I have an array containing 5 objects, all of which inactivated. These should then activate based upon the value of an int variable. If the int = 3, the three first objects should be activated. If int = 1, only the first one should be activated and so on. This int value will change during gameplay and so the objects needs to be able to dynamically adapt recordingly. How would I go about doing this? Thankful for any help!

You could have two components, one is a script that goes on the objects you want to be activated/deactivated, the other manages these components.

On the objects have a script called ObjectController (or whatever):

var activated = false;

function Activate() {
	// do whatever you need to do to activate
}

function Deactivate() {
	// do whatever you need to do to deactivate
}

And the script which controls them:

var numActivated:int = 0;

var objects = new ObjectController[5];

function Update() {
	var i = 0;
	
	// activate any unactivated ones that need to be activated
	for(; i < numActivated; i++) {
		if (!objects*.activated)*

_ objects*.Activate();_
_
}*_

* // deactivate the rest if they are activated*
* for(; i < objects.length; i++) {*
_ if (objects*.activated)
objects.Deactivate();
}
}*

Then in the inspector you can set the value numActivated (or change it programmatically at runtime). You can also drag the objects you want to be activated into objects so long as they have an ObjectController script attached._

This is pseudo code, based on c# assuming:

  1. your object to ‘activate’ has an ‘Activate’ method that thats no args.

  2. your objects are stored in an array called ‘arrayOfObjects’

  3. your ‘int’ is called ‘numToActivate’

    for(var i = 0; i < Math.Min(numToActivate, arrayOfObjects.Length); i++)
    {
    arrayOfObjects*.Activate();*
    }

var arrGo:GameObject;
var wrongamount:int;
var wrongamount2 :int;

function Update(){
   if(wrongamount!=wrongamount2){
      LampActivation(new);
      wrongamount=wrongamount2;
   }
}

function LampActivation(wrongamount2:int){
   for(int i = 0; i< wronglamp.Length; i++){
      wronglamp*.active = false;*

}
for(int i = 0; i< wrongamount2; i++){
wronglamp*.active = true;*
}
}
I first deactivate them all and reactivate the needed one.
Now my issue is where is this going to be attached. You will have to access the array differently depending where you put that one. But the process should be as such I guess.