Affect All Instances Of A Prefab

Hey guys, thanks for taking a look at my question. Basically, I am using the

gameObject.Find("Object").GetComponent(Script).enabled=false

thing. I want to disable a script on all instances of a prefab, but this only affects the main object, not everything.

gameObject.FindWithTag

doesn’t work either. To sum up, I would like to find a way to disable a component, or this case a script, on all instances of a prefab. Thank you :D.

there are a coupple of ways you can do this:

1 is tagging all your your objects a certain prefab.

and than call it:

GameObject[] GOs = GameObject.FindGameObjectsWithTag("TagName");
// now all your game objects are in GOs,
// all that remains is to getComponent of each and every script and you are good to go.
// to disable a components
for (i=0; i<GOs.Length; i++){
    // to access component - GOs*.GetComponent.<BoxCollider>()*

// but I do it everything in 1 line.
GOs*.GetComponent.().enabled = false;*
}
another method is to use static variables or for your case function.
static void FunctionToDeactivateAllScripts(){
this.enabled = false;
}
now when you call this function from anywhere ALL scripts containing this function will be disabled, because only 1 function exists.

You could try (C#):

GameObject[] gos = GameObject.FindGameObjectsWithTag("TagOnObjects");
foreach(GameObject go in gos)
{
   	go.GetComponent<NameOfScript>().enabled = false;
}

If you for some reason need to change it through prefabs, take a look at PrefabUtility.

if you disable the script in only one prefab, that affects all other.

something like this:

if(something)
Object(Prefab).GetComponent<Script>().DoSomething();