- Home /
Disable the function timer?
Hello Everyone,
I'm trying to disable the function timer in my script. I'm using this script to show some GUI.Text while my mouse is over my GUI button or Rect.
But now is flashing. I want to disable that function and only active the GUI Text while the mouse is over the Rect or button.
I did try but without success.
Please any advice is more than welcome.
Thanks!
private var timer : float = 0.0;
function Update(){
if(guiText.enabled){
timer += Time.deltaTime;
if(timer >=0.5){
guiText.enabled = false;
timer = 0.0f;
}
}
}
function ShowHint(message : String){
guiText.text = message;
if(!guiText.enabled){ guiText.enabled = true; }
}
Answer by Wolfram · Feb 07, 2013 at 03:54 AM
You mean flashing really fast (=every frame) or moderately fast (=every 0.5 seonds)?
Your countdown starts immediately as soon as ShowHint() gets called. You did not describe how that is called, but if it's via OnMouseOver(), then your problem is right there: OnMouseOver(), and therefore ShowHint(), is called every frame, as the docs say.
Since I assume you don't want your text shown just for 0.5 seconds, I guess the idea is to have it still display for 0.5s after you moved the mouse away? If that is correct, then the quickest way to solve it is to add "timer=0;" to ShowHint(), for example at the end (but noth within the "if"). This way you'll keep your timer at 0 (and therefore the gui enabled) while the mouse is over your object.
If you really don't need the timer, remove the Update() completely, and ins$$anonymous$$d in your calling function do something like:
if(...mouse coordinate testing...){
Send$$anonymous$$essage("ShowHint",...);
showing$$anonymous$$essage=true;
}else if(showing$$anonymous$$essage){
Send$$anonymous$$essage("HideHint");
}
And then add to the other script:
function HideHint(){ guiText.enabled=false; }
It will give you better performance.
Your answer
Follow this Question
Related Questions
GUI elements vanish when publishing 1 Answer
Score going up every second 1 Answer
GUIText not working properly with a timer. 1 Answer
How to stop a timer with GUI button? 1 Answer
A node in a childnode? 1 Answer