How can I Disalbe/Activate some scripts if i press a specific key?
so?
function Update() {
if (Input.GetKeyDown(KeyCode.X)) {
ScriptName.enabled = !Input.GetKey(yourKey);
ScriptName.disable = !Input.GetKey(yourKey);
}
How can I Disalbe/Activate some scripts if i press a specific key?
so?
function Update() {
if (Input.GetKeyDown(KeyCode.X)) {
ScriptName.enabled = !Input.GetKey(yourKey);
ScriptName.disable = !Input.GetKey(yourKey);
}
You cannot attach this code to the script you want to disable because once disabled, it will no longer check for input. The way to get around this is to make a second script that will disable the first script. This second script will need to be something like (untested code):
var scriptToControl : nameOfScriptToControl;
function Start () {
scriptToControl = GetComponent("nameOfScriptToControl");
}
function Update() {
if (Input.GetKeyDown(KeyCode.X)) {
Debug.Log("User pressed X");
if (scriptToControl.enabled)
scriptToControl.enabled = false;
else
scriptToControl.enabled = true;
}
}