• 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
1
Question by Jeff Ciaccio · Jun 24, 2010 at 12:51 PM · time

How to make a label appear for a set amount of time

I have a projectile, and I want to label its position at various points, but I only want that lable to last for a couple of seconds and then go up in a poof of smoke.

I tried a while loop with Time.time <= startTime + 2, but this just caused Unity to freeze.

Mike mentioned a co-function, but I'm not sure how to go about that.

Thx

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 Mike 3 · Jun 24, 2010 at 12:54 PM

I'll just copy paste my other answer which should work:

change this

if (GUI.Button (Rect (20,40,80,20), "Level 1"))
{
    print( "you hit LoadLevel (1), but this does nothing yet");
    test = true;
    timeWhenPushed = Time.time;
    print ("You pushed the button at " + timeWhenPushed);
    while (Time.time <= timeWhenPushed +1)
    {
        GUI.Label(Rect (120, 40, 200, 40), "You hit level 1");
    }
}

to this:

if (GUI.Button (Rect (20,40,80,20), "Level 1"))
{
    print( "you hit LoadLevel (1), but this does nothing yet");
    test = true;
    timeWhenPushed = Time.time;
    print ("You pushed the button at " + timeWhenPushed);
}
if (Time.time <= timeWhenPushed +1)
{
    GUI.Label(Rect (120, 40, 200, 40), "You hit level 1");
}
Comment
Add comment · Show 3 · 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 Jeff Ciaccio · Jun 24, 2010 at 01:07 PM 0
Share

Sorry $$anonymous$$ike, I must have missed (or forgotten) this. So it looks like all you changed was the while to an if. Why won't the while work? (Please forgive my ignoragnce) Thanks!

avatar image Jeff Ciaccio · Jun 24, 2010 at 01:11 PM 0
Share

Looks like you did answer this :) Once it scrolled off the screen, I thought it was gone (or would just go unanswered).

If I put a comment in an old question, will it pop back up to the top of the questions again??

avatar image Mike 3 · Jun 24, 2010 at 01:29 PM 0
Share

No, but it pops up in the message section for me

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

In game clock/Time 1 Answer

difference with Time.time, Time.deltatime, Time.frameCount 3 Answers

How does Unity handle time scheduling? 1 Answer

Spawn after every 5 seconds 4 Answers

Clamp animation to a certain amount of time? 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