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 Rob333 · Jun 06, 2012 at 03:27 AM · delayonguitime.time

Beginner needs help with a scripting question please

Can anyone show me how to get this script working with the "commented out" lines included. It works as it is but I can't manage to get it to work with a delay before loading the level.

I've tried different ways to set the script out, I'm still only a beginner.

 var StartTime : float;
 var customSkin:GUISkin;
 
 function OnGUI (){   
     if(GUI.Button(Rect(0,0,100,50),"Play Game")){  
         //  StartTime = Time.time + 3;
         //  if (Time.time-StartTime >= 3);{
         Application.LoadLevel ("game") ;
     } 
 }
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 Berenger · Jun 06, 2012 at 03:37 AM

The code inside if(GUI.Button(...)) will be executed only at the exact frame you release the mouse at the end of the clic. If you want to wait, you must do it somewhere else.

There is several way. The simplest is to use Invoke, with 3 as the second parameter. Declare a function that only call LoadLevel and give it's name as a string for parameter one. Like this :

 function OnGUI(){
     if(GUI.Button(Rect(0,0,100,50),"Play Game")){  
         Invoke( "WaitAndLoad", 3.0 );
     } 
 }
 
 // You can choose another name, but it must match with the one in Invoke
 function WaitAndLoad(){
     Application.LoadLevel ("game") ;
 }

There is another way, just a tiny bit more complicated. For now stick with this one, and keep the words coroutine and yield in a corner of your mind for when you feel more comfortable.

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 Rob333 · Jun 08, 2012 at 03:55 AM 0
Share
 Thanks for that Berenger, I will try it out.
avatar image Bunny83 · Jun 08, 2012 at 03:58 AM 0
Share

@Rob333: First, don't post this as answer! Answers should answer the question. I've converted your answer into a comment.

Second, you don't have enough karma to directly post to this site. Your posted will be placed into the moderation queue. Every user with 1000+ karma can publish your posts, but you have to wait until someone can find the time to do so. Don't post the same thing multiple times.

avatar image Rob333 · Jun 10, 2012 at 12:23 PM 0
Share

Thanks for the help Berenger, your script worked in my test project but still can't make it work in my main project. I've just posted a new question with details of what's happened, tile of question is "Unusual problem loading a scene".

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using Time with OnGUI Help 2 Answers

Time.time button delay trick causing NaN 0 Answers

How to add delay before showing GUI Button? 3 Answers

Clickable Scrollable List? 1 Answer

MouseOver GUI.Label Information 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