• 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 SUPPEAR · Mar 21, 2015 at 04:39 AM · android2dscenetimerloadlevel

How to load a level after 30 seconds?

Hello. I am making a game that is intended for the Android and is 2D. I can't figure out how to load a level after 30 seconds. The game is supposed to last only 30 seconds and then is suppose to take you to a different scene ( Level ).

The script I am using is

 using UnityEngine;
 using System.Collections;
 
 public class Clock : MonoBehaviour {
 
     int hours;
     public int hours24;
     public float minutes;
     public int iMinutes;
     string fMinutes;
     string ampm;
     
     TextMesh clockText;
     
     void Start () {
         clockText = GetComponent<TextMesh> ();
         hours = 12;
         hours24 = 12;
         minutes = 01;
         ampm = "pm";
         
     }
     void Update () {
         // Build Time. Default is one minute per second.
         minutes += Time.deltaTime; 
         iMinutes = (int) minutes ;
         fMinutes = iMinutes.ToString("D2");
         
         
         if (iMinutes >= 60) 
         {
             if (hours == 12)
             {    
                 hours = 0;
             }
             if (hours == 11)
             {    
                 if (ampm == "am")
                     ampm = "pm";
                 else
                     ampm = "am";
             }
             
             if (hours24 == 23)
                 hours24 = 0;
             
             hours +=  1;
             hours24 += 1;
             iMinutes = 0;
             minutes = 0;
             
         }
         
         clockText.text =  fMinutes ;
     }
     
 }

The counter works with Iminutes w$$anonymous$$ch are called minutes but count in seconds.

How can I modify the script that when the Iminutes reaches 30 a different scene loads.

All help is appreciated. If there are any questions, please ask.

Comment
Add comment · Show 3
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 Priyanshu · Mar 21, 2015 at 04:57 AM 0
Share
avatar image SUPPEAR · Mar 21, 2015 at 05:51 AM 0
Share
avatar image alok-kr-029 · Mar 21, 2015 at 08:00 AM 0
Share

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Priyanshu · Mar 21, 2015 at 06:13 AM

If you are having such a problem:

  1. You need to learn about conditional statements in c#.

  2. You can learn to use Application.LoadLevel here.

To modify the script that, when the Iminutes reaches 30 a different scene loads.

You need to add the following 'If' statement inside Update() in the end :

 if( iMinutes >= 30)
 { 
     //You need to pass Level index or Level name in the method.
     Application.LoadLevel(x); 
 }

Now,

  1. Press ctrl+s$$anonymous$$ft+b, if working in windows to open the Build Settings window.

  2. Add your scenes there. By pressing the Add Current button or drag and dropping scenes from Project window into Build Settings Window.

  3. Note the name or Integer value infront of the scene name.

  4. Replace 'x' in Application.LoadLevel(x); with it.

  5. For example: replace 'x' with "Test Scene" or simple "0".

    Application.LoadLevel(Test Scene); Or Application.LoadLevel(0);

alt text


untitled.png (20.6 kB)
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 SUPPEAR · Mar 21, 2015 at 07:53 AM 0
Share
avatar image Priyanshu · Mar 21, 2015 at 08:22 AM 0
Share
avatar image SUPPEAR · Mar 21, 2015 at 08:18 PM 0
Share
avatar image
0

Answer by Ghopper21 · Mar 21, 2015 at 04:54 AM

When the time reaches 30 seconds, execute Application.LoadLevel()

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 Johnz1234 · Mar 21, 2015 at 10:40 AM

  #pragma strict
   var time : float = 0;
  function Start() {
      time = 5;
  }
   
  function Update () {
      if(time > 0){
         time-=Time.deltaTime;
      }else{
         Application.LoadLevel("Level1");
      }
  }
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.

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

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

Related Questions

Game freeze while I click Gui texture loadlevel to change scene 0 Answers

Android: Scene change (Application.LoadLevel) has no effect 3 Answers

Application.LoadLevel Strange Problem 2 Answers

Game looks different on device compared to Game View 0 Answers

How to create a timer with the new UI text? 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