Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Grady · Jul 01, 2011 at 08:59 AM · guidistancelabeltimed

how to script a timed GUI Label into my script

Hey guys,

I have this script so far, and what i want to do is make a timed GUI Label, so that when the player comes into range of the "objective" variable (this script is attached to the player) then it displays a GUI Label that only lasts for a couple of seconds....

 var objective : Transform;
     
     function OnGUI{
     
     if (Vector3.Distance(transform.position, objective.position) < 3000){
     
     }
     }

I have tried using the yield method (http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html), but that doesn't seem to work entirely...

any answers would be greatly appreciated!!!!

-Grady

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
0

Answer by GuyTidhar · Jul 01, 2011 at 09:21 AM

 var objective : Transform;
 var showLabel : boolean = false;
 var timeUntilHide : float;
 
 function Update()
 {
    if (Vector3.Distance(transform.position, objective.position) < 3000 )
    {
      if ( !showLabel )
          StartCotourine("ShowAndWaitUntilHide");
    }
    else if ( showLabel )
    {
      StopCoroutine("ShowAndWaitUntilHide");
      showLabel = false;
    }
 }
 
 function OnGUI
 {
    if ( showLabel )
      GUI.Label(Rect(10,10,20,20), "MyText");
 }

 function ShowAndWaitUntilHide()
 {
   timeUntilHide = 5;
 
   showLabel = true;
 
   while ( timeUntilHide > 0 )
   {
     // Wait 1 frame before returning to this loop
     yield;

     timeUntilHide  -= Time.deltaTime;
   }
 
   showLabel = false;
 }
Comment
Add comment · Show 7 · 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 Grady · Jul 02, 2011 at 01:58 AM 0
Share

i tested the script above, and the gui text appears when i get into within 3000 of the objective, but it doesn't dissapear???? how would i make it dissapear after about 5 seconds????

thanks

-Grady

avatar image GuyTidhar · Jul 02, 2011 at 07:39 AM 0
Share

I've changed the script. Also - make sure you do not set showLabel to false in another location as here.

avatar image Grady · Jul 02, 2011 at 08:04 AM 0
Share

i don't know if i've done something wrong, but it all works fine, until i get in range of the target. when i get in range, it appears fine, but after the 5 seconds it will flicker, and then reappear, and repeat... it will stay for another 5 seconds and then flicker???? i've tried having the "Show Label" variable ticked and unticked in the inspector, as well as manually entering the "Time Until Hide" variable

-Grady

avatar image GuyTidhar · Jul 02, 2011 at 08:10 AM 0
Share

Did you copy the new script? I've made a big change here...

avatar image Grady · Jul 02, 2011 at 08:48 AM 0
Share

yeah i did....

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

GUI in the middle of the screen 1 Answer

GUI Label script problem??? 1 Answer

Creating a component from a button click 1 Answer

Get variable from another object 1 Answer

disable code when level is rendered 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