script enable=false
Hello All, I have been looking up and down for a simple jscript to disable a script on another object. Seems active or enabled doesnt work in function update unless im missing something which im sure might be the case as im relatively new to scripting. If someone has a hint or script i could follow for unity5 that would be great, in the meantime i'll keep searching. Thankyou.
Answer by phatpixels · Oct 21, 2015 at 10:31 AM
seems i was doing it wrong....... this is correct js
cube.GetComponent( move2 ).enabled = false;
this didnt work
cube.GetComponent( "move2" ).enabled = false;
thankyou all for your help :-)
Hey there. I see you're using JavaScript, C# runs faster on the Unity engine (JavaScript can also sometimes be faster).
To do this you should be creating a variable beforehand with cube.GetComponent("move2").
Also, C# method is:
private move2 FOOBAR;
void Start ()
{
FOOBAR = cube.GetComponent<move2>();
}
void Update ()
{
FOOBAR.enabled = false;
}
Answer by LucasVmarrewyk · Oct 21, 2015 at 10:24 AM
Hey there,
Have you tried: scriptName.SetActive(true); ?