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 Entyro · Dec 30, 2012 at 01:39 PM · timerguitextdissapear

GUIText dissapear after a few seconds

Hi. I was just wondering how to make a GUIText dissapear after a few seconds. I have this script right now that triggers a GUIText when I walk over a triggered area.

 var theGuiObject : GUIText; // set this in the inspector view
 
 function OnTriggerEnter (other : Collider) {
     if (other.CompareTag ("Player")) {         
         theGuiObject.enabled = true;
     }
 }
 
 function OnTriggerExit (other : Collider) {
     if (other.CompareTag ("Player")) {         
          theGuiObject.enabled = false;
     }
 }
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

2 Replies

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

Answer by Eric5h5 · Dec 30, 2012 at 08:44 PM

You'd want to handle the case of the player entering the trigger, leaving, then re-entering.

 var theGuiObject : GUIText;
 var displayTime = 3.0;
 private var timerActive = false;
 private var timer = 0.0;
 
 function OnTriggerEnter (other : Collider) {
     if (!other.CompareTag ("Player")) { // Do nothing if tag is not "Player"
         return;
     }
     if (timerActive) { // Reset timer if player re-enters trigger while the timer's active
         timer = 0.0;
         return;
     }
     
     theGuiObject.enabled = true; // Enable GUIText, wait a while, then disable it
     yield Wait();
     theGuiObject.enabled = false;
 }
 
 function Wait () { // A custom WaitForSeconds coroutine that can be reset
     timerActive = true;
     timer = 0.0;
     while (timer < displayTime) {
         timer += Time.deltaTime;        
         yield;
     }
     timerActive = false;
 }
Comment
Add comment · Show 5 · 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 m4s4m0r1 · Dec 31, 2012 at 02:28 AM 0
Share

ok, this is the true answer... $$anonymous$$ark it as true answer... i `m lose now :)

avatar image Entyro · Dec 31, 2012 at 10:16 AM 0
Share

I guess this would work but the text is still there for me. I'm using this script for a battery pick-up. The trigger destroys after I walk in to the triggered area and then the text pops up. Can the problem be that the trigger destroys or what?

avatar image Eric5h5 · Dec 31, 2012 at 10:19 PM 0
Share

Don't destroy the trigger, because then the script is destroyed with it and the code can't run because it doesn't exist anymore.

avatar image Entyro · Jan 01, 2013 at 01:04 PM 0
Share

But I just want to use the trigger once, not multiple times

avatar image Eric5h5 · Jan 01, 2013 at 05:32 PM 0
Share

Don't destroy it until after the script is no longer needed, then.

avatar image
0

Answer by m4s4m0r1 · Dec 30, 2012 at 03:07 PM

i think you can use yeild WaitForSeconds maybe like this :

 function OnTriggerEnter (other : Collider) {
     if (other.CompareTag ("Player")) {         
         theGuiObject.enabled = true;
         WaitToDisappear();
     }
 }
 function WaitToDisappear()
 {
    yield WaitForSeconds(//set your time in here)
    theGuiObject.enabled = false;
 }
Comment
Add comment · Show 1 · 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 Entyro · Dec 30, 2012 at 04:04 PM 0
Share

Didn't work. The text is still there.

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

9 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

GUIText not working properly with a timer. 1 Answer

Score System help 1 Answer

RPG Levelling Script using GUI Text help 0 Answers

Having problems with my timer 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