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 Paige · Mar 21, 2011 at 11:35 PM · guicheckpoint

Checkpoint GUI enabled then disabled trouble

Hey, I have been trying to create a checkpoint GUI box that pops up for about 3 seconds to say the player hit a checkpoint, and then disappear. i have been messing around with this for days and looking at other people's ideas for turning GUIs off, to no avail. i already have the checkpoint GUI pop up when i run into a collider, Im now only having trouble turning it off. this was my last failed attempt, mostly due (i believe) to the yield object not working in the GUI function:

function OnGUI() { if(check) { GUI.Box(Rect(Screen.width - 100,0,100,50), "Check Point"); timer = 1; }

     if(timer == 1)
     {
     yield WaitForSeconds(3);
     check = false;
     timer = 0;
     }

}

obviously, using javascript. any help would be greatly appreciated

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Mar 22, 2011 at 12:26 AM

var delay = 3.0; private var checkTime = 0.0; private var check = false;

function TurnOnCheck() { checkTime = Time.time; check = true; }

function OnGUI() { if (check) GUI.Box(Rect(Screen.width - 100,0,100,50), "Check Point"); if ((Time.time - checkTime) >= delay) check = false; }

Call TurnOnCheck() somewhere, like when your checkpoint is reached.

Comment
Add comment · 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
0

Answer by tool55 · Mar 22, 2011 at 12:34 AM

Perhaps you need to amend your if statement:

if (check && !timer)
Comment
Add comment · 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
0

Answer by Eric5h5 · Mar 22, 2011 at 12:48 AM

It's much simpler and more efficient if you enable and disable the script as appropriate. You should make the script disabled in the inspector by default, so it's only enabled when you call the ShowGUI function with the time you want it to be displayed.

function OnGUI() { GUI.Box(Rect(Screen.width - 100,0,100,50), "Check Point"); }

function ShowGUI (timer : float) { enabled = true; yield WaitForSeconds (timer); enabled = false; }

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

About "How do I make laps in a racing game?" 2 Answers

Change Font Style OnMouseEnter 0 Answers

GUIDrawTexture Based Crosshairs 0 Answers

When I pause my game and enable canvas and then resume my keyboard starts controlling the menu... 1 Answer

How to know if something is selected in Hierarchy or in project. 5 Answers


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