How do i Enable / Disable Scripts of another Objects. I tried it with GameObject.Find("Object").GetComponent(Script).enabled = true;
but Unity gives me an error :
‘enabled’ is not an member of ‘UnityEngine.GetComponent’
I googled serveral times how to do it. But i never found a solution that Worked. And the solutions were old. (2010-2013)
Please Help.
2 Answers
2Try making a variable for the object instead of finding it so it would me like
JavaScript:
var Object1 : GameObject;
Object1.GetComponent(ScriptName).enabled = true;
c#:
Public GameObject Object1;
Object1.GetComponent<ScriptName>.enabled = true;
don’t forget to assign the object that has the script you want to enable/disable in the inspector
note: not sure if c# will work I use JavaScript
tell me how it went with you
If you want find gameobject with tag write this
GameObject.FindGameObjectWithTag("TagName").GetComponent(ScriptName).enabled = false;
That C# is incorrect. It should be:
– HoeloeObject1.GetComponent < ScriptName > ().enabled = true;Also, I think the argument to GetComponent should be a string if you're not using the generic version (though I highly suggest you do), which would confuse the compiler. Not sure about that though.