Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by paco morales · Feb 07, 2013 at 03:20 AM · guitimerguitext

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; }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image paco morales · Feb 07, 2013 at 04:18 AM 0
Share

Thanks $$anonymous$$an is working :)

avatar image Wolfram · Feb 07, 2013 at 04:27 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges