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 AnomalousX12 · Feb 10, 2014 at 04:00 PM · androidjavascriptcoroutinebuttonsongui

How do I delay the appearance of these buttons?

 function OnGUI() 
 {
     GUI.Box(Rect(((Screen.width)/2)-45,(((Screen.height)/2)-25)-60,90,50), "Score: " + playerScript.score, fontVar); //Shows user's score (I want that to show immediately)

//I want the pause here. I've tried yield WaitForSeconds(1); but it tells me that OnGUI() cannot be a coroutine.

     if(GUI.Button(Rect(((Screen.width)/2)-45,(((Screen.height)/2)-25),90,50), "Play Again"))
     {
         Application.LoadLevel("sceneLevel1");
     }
     
     if(GUI.Button(Rect(((Screen.width)/2)-75,(((Screen.height)/2)-25)+60,150,50), "Return to Main Menu"))
     {
         Application.LoadLevel("sceneScreenMainMenu");
     }
     
     if(GUI.Button(Rect(((Screen.width)/2)-45,(((Screen.height)/2)-25)+120,90,50), "Exit Game"))
     {
         Application.Quit();
     }
 }
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
0
Best Answer

Answer by AnomalousX12 · Feb 10, 2014 at 05:22 PM

Updated answer. This has actual time functionality. Once again, my C# Visual Studio friend helped me. Why were all of the answers here so much more complicated?

 function OnGUI() 
 {
     //Initial code
     if(Time.time < 1)
     {
     }
     else
     {
     //Delayed code
     }
 }
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 poncho · Feb 10, 2014 at 07:53 PM 0
Share

this is functional, BUT this is kinda difficult to track the time, since a second could have 6-7 OnGUI updates even more if lots of elements in scene, if you are going to use this method change it for

 if(counter < 60)
 counter++;
 else
 {
 ///your code...
 }

this avoid to make unnecesary additions and stops an overflow of counter variable(which it would take about 9 years to happen at pace of 7 per second...)

avatar image AnomalousX12 · Feb 10, 2014 at 08:05 PM 0
Share

Awesome! I implemented that. Is there no delta time use that I could fix the issue you have with this method?

avatar image AnomalousX12 · Feb 11, 2014 at 06:04 PM 0
Share

Updated the answer. This seems to be perfect, now.

avatar image DajBuzi · Feb 11, 2014 at 06:12 PM 0
Share

Is this "newer verion even works? From what i know Time.time returns time that passed since level was started. So it would be almost every time greater than 1.

avatar image AnomalousX12 · Feb 11, 2014 at 06:14 PM 0
Share

It works perfectly from what I can see so... I dunno.

Show more comments
avatar image
1

Answer by DajBuzi · Feb 10, 2014 at 04:13 PM

I would do it like this:

 //first i would set time offset and some kind of "checker" to know if time was set
 public float dispOffset = 1.0f;
 private bool tikeWasSet;
 // ...
 // next you need action to set when to display theM
 if(someKindOfActionWasDone){
     timeToDisplay = Time.time + dispOffset;
     timeWasSet = true;
  }

 void OnGUI(){
     if(timeWasSet && Time.time >= timeToDisplay){
        //your delayed code here
     }
 }
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 AnomalousX12 · Feb 10, 2014 at 04:39 PM 0
Share

Huh... That just seems so much more complex than what I thought would be needed :[ Is there really no simpler way? I don't even know what a lot of that stuff kinda meant. Like Time.time.

avatar image poncho · Feb 10, 2014 at 05:14 PM 0
Share

this is the right answer, a simpler way could be a yield waitForSeconds, but it will stop OnGUI, still, you have to read a little documentation like Time.time, to know what they are and what you can do with them

avatar image AnomalousX12 · Feb 10, 2014 at 05:23 PM 0
Share

I believe my friend came up with a simpler answer. I submitted it as an answer for other people who have this question.

avatar image
0

Answer by JeffreyD · Feb 10, 2014 at 05:22 PM

How about... void OnGUI(){ Invoke ("DoMyButtonsDelayed", 1.50f); // delay time is second argument }

void DoMyButtonsDelayed() { //your delayed code here }

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I fix this Coroutine Camera? 1 Answer

Enemy AI; Run away from player (x and y) 1 Answer

How do i need to change this script for mobile? 1 Answer

game won't work in build 0 Answers

Wiggle Or shake button possible? 2 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