Haikai
1
Hello!
I’ve read all topics about it but somehow I cannot make it work.
How can I disable a script using javascript in Unity 5+?
ScriptName.enabled = false;
GetComponent(“ScriptName”).enabled = false;
GetComponent(ScriptName).enabled = false;
None of the above codes are working for me.
Thanks if you can help.
Eric5h5
2
GetComponent(ScriptName).enabled works fine, no different than other versions. Nothing changed regarding that. You have some other issue.
Hellium
3
The documentation is quite self explanatory
You surely do something wrong in your script. Make sure you are referencing the right script.
With these very simple scripts, everything works
// MyScript.js
var otherScript : Rotate;
function Update () {
if( Input.GetKeyDown( KeyCode.Space ))
otherScript.enabled = !otherScript.enabled ;
if( Input.GetKeyDown( KeyCode.A ))
GetComponent.<Rotate>().enabled = !GetComponent.<Rotate>().enabled ;
}
// Rotate.js
#pragma strict
function Update () {
transform.Rotate(Vector3.up * Time.deltaTime * 50, Space.World);
}