I have a button and when its clicked some animation happens. What I want to do is after clicking the button, user should not be able to click the same button for upcoming 2 seconds. Just like blocking button click for next 2 seconds and then again activating the button for animation.
May I know how would I do this?
something like this
That was an interesting approach. I think that will work. and yes I forgot to mention one thing. I have texture over the button. So user will have this feeling of button being there but its inactivated for some interval of time.
GUI.enabled = false will make a nicely dimmed out and unclickable button.
Your code could look something like
var CLICKABLE_DELAY : float = 2.0;
private var isButtonClickable : boolean = true;
function OnGUI() {
GUI.enabled = isButtonClickable;
if(GUI.Button())
ButtonClicked();
GUI.enabled = true;//otherwise all the rest of your GUI would be disabled too.
}
private function ButtonClicked() {
isButtonClickable = false;
//various code here
yield WaitForSeconds(CLICKABLE_DELAY);
isButtonClickable = true;
}