- Home /
Disable Button for a while
I want it so that when i press the mouse button, it disables it for some time with a WaitForSeconds. So what is the function to disable a mouse button?
Answer by Molix · Feb 23, 2010 at 09:38 PM
A simple way would be something like:
bool disableFiring = false; float firingDisableDuration = 5.0f; // or whatever time you want
void MouseButtonPressed() { if( !disableFiring ) { Fire(); disableFiring = true; Invoke("EnableFiring", firingDisableDuration ); } }
void EnableFiring() { disableFiring = false; }
I hope that helps.
Answer by Dwair · Feb 23, 2010 at 03:07 PM
I'm afraid you cannot "disable a mouse button" but disable the script that contains the call to GetMouseButton.
In your program, simply use a boolean variable (depending on the structure of your program, maybe it will need to be static) that gets changed to false everytime you click, and check for it just before you call GetMouseButton.
Then, you can wait for waitForSeconds to reset your boolean to true again...
I'm sure there are more elegant approaches than that, try to centralize all the mouseButton calls in a script to keep things tidy.
I added a variable to my script called "canShoot". It will check if its true before shooting, and it will make itself false after shooting. Now, when i try to make it WaitForSeconds, my character will just freeze in place, probably because i'm making the entire object wait. Any suggestions as to only having the wait effect the actual variable that needs to be reset to true?
If your character control script is where you use Get$$anonymous$$ouseButton, you shouldn't disable the entire script, but only check for the variable and call Shoot funcion if your canShoot variable is true and your Get$$anonymous$$ouseButton is also true.
Simpler solution if you ask me ;)
Hope this helps, and if it doesn't, can you put the code here?
Your answer
Follow this Question
Related Questions
How can i disable left button mouse, when i click on GameObject? 2 Answers
Disable/enable script and animation when you move your mouse cursor 1 Answer
Suspend Mouse Look 2 Answers
how to check if cursor is over as button? 2 Answers
While mouse is pressed and moved to a button, button should be pressed as well 0 Answers