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 sera0506 · Feb 16, 2015 at 01:40 PM · scenechangeloadlevelswitch

switching scenes by loadlevel, back to previous scene I got a problem

this is my test video link text


Hello~ I test loadlevel command.

I have two scene:

1>Unity-chan SecondaryAnimation

2>I wrote a scene -runGame

flow chart: SecondaryAnimation -by Click btn->runGame-game over->SecondaryAnimation

first switch SecondaryAnimation -->runGame

I change scene at video 18 sec.

runGame works perfectly.

second switch runGame-->SecondaryAnimation I change again in 35 sec. In video you can see SecondaryAnimation not work... only Click button can do loadlevel, but scene is not work successfully.

what should I do?

I use Unity 4.3 .

Thank you very much

↓ is part of code ↓


GameController.cs for runGame

 using UnityEngine;
 using System.Collections;
 
 public class GameControlScript : MonoBehaviour {
     float timeRemaining = 10;   //Pre-earned time
     float timeExtension = 3f;   //time to extend by on collecting powerup
     float timeDeduction = 2f;   //time to reduce, on collecting the snag
     float totalTimeElapsed = 0;   
     public float score=0f;      //total score
     public bool isGameOver = false;  
     public GUISkin skin;
 
     // Use this for initialization
     void Start () {
         Time.timeScale = 1;
     }
     
     // Update is called once per frame
     void Update () {
         if(isGameOver)
         {
             return;
         }
 
         totalTimeElapsed += Time.deltaTime;
         score = totalTimeElapsed*100;
         timeRemaining -= Time.deltaTime;
         if(timeRemaining <= 0)
         {
             isGameOver=true;
         }
     }
 
     void OnGUI()
     {
         GUI.skin=skin;
         if(!isGameOver)
         {
             GUI.Label(new Rect(10,10,Screen.width/3, Screen.height/3),"Time Life: " + ((int)timeRemaining).ToString());
             GUI.Label(new Rect(Screen.width-(Screen.width/3), 10, Screen.width/3, Screen.height/3), "Score: "+((int)score).ToString());
             //PlayerPrefs.SetString("score",""+(int)score);
         }
         else
         {
             Time.timeScale=0;
             //set the timescale to zero so as to stop the game
             //display the final score
             GUI.Box(new Rect((Screen.width/4)-20, Screen.height/5, Screen.width/2, Screen.height/2), "GAME OVER\nYour Score: "+(int)score);
 
             if(GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+3*Screen.height/10+10, Screen.width/2-20, Screen.height/10),"Exit Game"))
             {
 
                 //Debug.Log("****************"+PlayerPrefs.GetString("score")+"*********************");
                 //Destroy(GameObject.Find("runroot"));
                 //Application.LoadLevel(0);
                 Application.LoadLevel ("SecondaryAnimation");
             }
 
         }
     }
 
     public void DonutCollected()
     {
         timeRemaining += timeExtension;   //add time to the time remaining
     }
     
     public void OnionCollected()
     {
         timeRemaining -= timeDeduction;   // deduct time
     }
 }
 


CameraController.cs from Unity-chan's MainCamera

 void OnGUI()
         {
             if(showInstWindow){
                 GUI.Box(new Rect(Screen.width -210, Screen.height - 100, 200, 90), "Camera Operations");
                 GUI.Label(new Rect(Screen.width -200, Screen.height - 80, 200, 30),"RMB / Alt+LMB: Tumble");
                 GUI.Label(new Rect(Screen.width -200, Screen.height - 60, 200, 30),"MMB / Alt+Cmd+LMB: Track");
                 GUI.Label(new Rect(Screen.width -200, Screen.height - 40, 200, 30),"Wheel / 2 Fingers Swipe: Dolly");
             }
             if (Application.loadedLevelName.Equals ("SecondaryAnimation")) {
                                 if (GUI.Button (new Rect (Screen.width / 2, 70, 100, 30), "Click"))
                     Application.LoadLevel ("runGame");
                         } 
             else {
                 if (GUI.Button (new Rect (Screen.width / 2, 70, 100, 30), "Click"))
                     Application.LoadLevel ("SecondaryAnimation");
                         }
 
         }
 





Comment
Add comment · Show 1
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 sera0506 · Feb 17, 2015 at 08:08 AM 0
Share

I modify the code. It's work~! the problem in GameController.cs. I add Time.timeScale=0; that make scene can't work.

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

How to keep certain information when reloading a level 8 Answers

Touch button to load scene, instead of touching anywhere on screen 1 Answer

How do you switch scenes? PLZ HELP!!! 3 Answers

Change to scene based on current scene 1 Answer

Change scene automatically without collider/trigger 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