- Home /
How to deactivate something when holding down a key?
I need to know how to make it so that a script is deactivated when mouse0 is held down and the script is activated when mouse0 isn't being held down. Here is my script. The script is disabled on mouse0 but doesn't become re-enabled when mouse0 is released. I am using javascript btw.
var scare : follow; //this is my script
function Update () {
if (Input.GetMouseButton(0)){
if (scare.enabled == true)
scare.enabled = false;
}
}
Answer by robertbu · Feb 22, 2013 at 07:30 AM
var scare : boolean;
function Update () {
if (Input.GetMouseButtonDown(0))
scare.enabled = false;
if (Input.GetMouseButtonUp(0))
scare.enabled = true;
}
Untested, but this should do it.
Thanks a lot. It works perfectly for the script but it doesn't work for my mesh renderers but that wasn't my question lol.
Good suggestion. That's the way I do it too. There's probably a better built in way to do it though that's more reliable at high speeds....
Your answer
Follow this Question
Related Questions
How do I change the text of a GUIText object through another GameObject using a variable? 2 Answers
Can a script enable components? 2 Answers
GameObject variable change for all of the objects 1 Answer
{Easy question} How to disable script from other gameObject. 2 Answers
Enable script from other component. 1 Answer