Disabling scripts in multiple taged game objects ???

Hi guys, I need to write some code to disable a script in multiple game objects with a certain tag, its not working so far, any help with this would be GREAT

var SoundPlacerdis1 : String ;
//var SoundPlacerdis2 : String ;
//var  SoundPlacerEn1 : String ;
var destroyus : String;
function OnMouseOver () 
{
 if (Input.GetMouseButtonDown(0))
 {
// var gos = GameObject.FindGameObjectsWithTag(destroyus);

//for (var go in gos)
// 
  var SoundBankdiss = gameObject.FindGameObjectsWithTag(SoundPlacerdis1).GetComponent(CreateonAny);
			for (var SoundBankdis in SoundBankdiss);
			SoundBankdis.enabled = false;
	}
	}		
//then 
/*{ 		 it doesn't work for some reason, just add as a seperate script 
	
					var SoundBankEn = gameObject.FindGameObjectsWithTags(SoundPlacerEn1).GetComponent(createonClick );
			SoundBankEn.enabled = true;
			 
    // Destroy(go);
			
}
  
 }
  */

Javascript not my strong suit, but here we go :slight_smile:

for (var SoundBankdis in gameObject.FindGameObjectsWithTag(SoundPlacerdis1))
{
SoundBankdis.GetComponent(CreateonAny).enabled = false;
}

Problem I believe was with trying to find the component of an array of gameobjects.

Thanks, I’ll try this out latter, I redesigned the code a bit so now it doesn’t need to disable the scripts , but it needs to change a var( figured instead of ruining 3 different scripts to do the same thing 3 slightly different ways, just put in a nice if switch , and send commands to change the value of i)

I still very much need the code your helping me with !
Will get back to you latter to tell you if this works !

It WORKS

Glad I could help :slight_smile:

Don’t know how, but it broke again, now in game I get this error message

“NullReferenceException: Object reference not set to an instance of an object
SoundBank.OnMouseOver () (at Assets/Crappy Scripts/Specific Scripts/SoundBank.js:22)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents()”

var Ivalue : float = 1 ;
var SoundPlacerdis1 : String ;

//var SoundPlacerdis2 : String ;

//var  SoundPlacerEn1 : String ;

var destroyus : String;

function OnMouseOver () 

{

 if (Input.GetMouseButtonDown(0))
{
 
 //gameObject.FindGameObjectsWithTag(SoundPlacerdis1);
for (var SoundBankdis in gameObject.FindGameObjectsWithTag(SoundPlacerdis1))

{

SoundBankdis.GetComponent(CreateOnTouchAlt).i = Ivalue;
SoundBankdis.GetComponent(CreateOnAlt).i = Ivalue;

}

    }
    }

Upon further investigation I found that this script will find ONLY one game object with said tag and change it …

In that instance, in line 22, it couldn’t find that component on your SoundBankdis object. Make sure all your gameobjects tagged SoundBankdis1 have that component.

If your foreach loop is bugging, then it will stop after the bug, so it only finding 1 tag is expected.

This is driving me nuts, I cut the script down to change one component, and I still get the error, I’ve checked and re-checked the game objects to make sure they have that component…

var Ivalue : float = 1 ;
var SoundPlacerdis1 : String ;

//var SoundPlacerdis2 : String ;

//var  SoundPlacerEn1 : String ;

//var destroyus : String;

function OnMouseOver () 

{

 if (Input.GetMouseButtonDown(0))
{
 
 //gameObject.FindGameObjectsWithTag(SoundPlacerdis1);
for (var SoundBankdis in gameObject.FindGameObjectsWithTag( SoundPlacerdis1 ))


{
//SoundBankdis.GetComponent(CreateOnTouchAlt).i = Ivalue;
//SoundBankdis.GetComponent(CreateOnAlt).i = Ivalue;
SoundBankdis.GetComponent( CreateOnAnyAlt ).i = Ivalue;

}

    }
    }

I REALLY want to do this the right way, but if I can’t figure it out I might just give each gameobject( only 4 ) its own tag and run their own scrip for each one

Came up with a nice work around , each object calls an empty game object that just tells that what their I should be …