Enable/Disable multiple objects attached to one script

hello guys

I have 4 enemies with the same prefab attached to one script
i disabled two of them using the same script by boolean variable
that can be controlled from unity interface

using this command

var enable = true;
gameObject.active = enable;

now how can i enable one enemy and let the other enemy disable by command from other script

As Slobdell said, each script will have another instance. This is a way to disable/enable all of the objects…

function DisableObjects() {
	
	var objectsDisabling : GameObject[];
    objectsDisabling = GameObject.FindGameObjectsWithTag("ChangeStates");  //"ChangeStates" is the TAG in which the game object you are interacting with has... you can change this to whatever you'd like, it's in the Inspector.
  
    for (var obj : GameObject in objectsDisabling)  { 
    	obj.active = false;   
    } 

}

function EnableObjects() {
	
	var objectsEnabling : GameObject[];
    objectsEnabling = GameObject.FindGameObjectsWithTag("ChangeStates");  //"ChangeStates" is the TAG in which the game object you are interacting with has... you can change this to whatever you'd like, it's in the Inspector.
  
    for (var obj : GameObject in objectsEnabling)  { 
    	obj.active = false;   
    } 

}

As stated in the script, you have to assign the tags correctly on the gameobjects. This is very simple to do, if you don’t know how just Google it.

After that, edit this script accordingly (put the right tag in the quotes) and then call on the functions when you want to enable/disable the objects.

I know this method,
It didnt work the other script cant find enemy script because the entire objet is disable,
I am thinking about disable the enemy script and enable it

And in other case this method didn’t help me,
because i want to enable a specific object not all of them

i used this code and its work

var enemyScript = GameObject.FindGameObjectsWithTag("enemy"); 
enemyScript[3].GetComponent(scriptEnemy).enabled = true;

where the number is the object’s order in Hierarchy

Even though it’s the same script there is going to be a seperate instance for each gameobject it’s attached to. So then you can just get the script from each individual enemy and change them independent of each other. For C#…

EnemyScript script = enemy.getComponent<EnemyScript>();
script.enable = true;