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
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 which 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

You need Application.LoadLevel method to load a level.

avatar image SUPPEAR · Mar 21, 2015 at 05:51 AM 0
Share

That wasn't what I meant, thanks for the responses although. I mean what do I write in order for it know for it to be done at 30 seconds.

avatar image alok-kr-029 · Mar 21, 2015 at 08:00 AM 0
Share

why dont you use StartCoroutine; yield return new waitforsecond(30f);

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+shift+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

Alright, I did as you have said ( Hopefully ), but I am getting these errors. ( Here is the Script)

 using UnityEngine;
 using System.Collections;
 
 public class Clock : $$anonymous$$onoBehaviour {
     
     int hours;
     public int hours24;
     public float $$anonymous$$utes;
     public int i$$anonymous$$inutes;
     string f$$anonymous$$inutes;
     string ampm;
     
     Text$$anonymous$$esh clockText;
     
     void Start () {
         clockText = GetComponent<Text$$anonymous$$esh> ();
         hours = 12;
         hours24 = 12;
         $$anonymous$$utes = 01;
         ampm = "pm";
         
     }
     void Update () {
         // Build Time. Default is one $$anonymous$$ute per second.
         $$anonymous$$utes += Time.deltaTime; 
         i$$anonymous$$inutes = (int) $$anonymous$$utes ;
         f$$anonymous$$inutes = i$$anonymous$$inutes.ToString("D2");
         
         
         if (i$$anonymous$$inutes >= 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;
             i$$anonymous$$inutes = 0;
             $$anonymous$$utes = 0;
             
         }
         
         clockText.text =  f$$anonymous$$inutes ;
     }
     if ( i$$anonymous$$inutes >= 30)
     { 
         //You need to pass Level index or Level name in the method.
         Application.loadedLevel();   
     }
 }

Here are the errors

Assets/Standard Assets ($$anonymous$$obile)/Textures/Clock.cs(61,1): error CS8025: Parsing error

Assets/Standard Assets ($$anonymous$$obile)/Textures/Clock.cs(59,40): error CS1519: Unexpected symbol (' in class, struct, or interface member declaration Assets/Standard Assets ($$anonymous$$obile)/Textures/Clock.cs(56,24): error CS1519: Unexpected symbol >=' in class, struct, or interface member declaration

Assets/Standard Assets ($$anonymous$$obile)/Textures/Clock.cs(56,10): error CS1519: Unexpected symbol `if' in class, struct, or interface member declaration

avatar image Priyanshu · Mar 21, 2015 at 08:22 AM 0
Share

sorry i used "Application.loadedLevel" ins$$anonymous$$d of "Application.LoadLevel".

And you get that error because you wrote that code outside Update(). Write it just below clockText.text = f$$anonymous$$inutes ;

You need to add scene in build setting and pass a value inside "Application.LoadLevel()"

Edited my answer

avatar image SUPPEAR · Mar 21, 2015 at 08:18 PM 0
Share

Thank you :)

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.

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

Why isn't this working? 3 Answers

Game looks different on device compared to Game View 0 Answers

Application.Loadlevel("Level Name"); not working on android 2 Answers

OpenIAB - billing plugin. It works only once! need HELP! 1 Answer

Game freeze while I click Gui texture loadlevel to change scene 0 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