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);
}
}
*/
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)
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;
}
}
}
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