Search Unity

After loading three scenes the thirth scene don't start

Discussion in 'Scripting' started by Barft, May 29, 2015.

  1. Barft

    Barft

    Joined:
    Apr 9, 2015
    Posts:
    84
    Hi guys, I'm working on a project, ik have made a menu button in the scene and when you click it, it open a canvas,panel with 2 buttons (the menu). One button is "back" , the other button is "All Levels" For the "All Levels" button I have made a new scene with all buttons to choose a level. So when you click on the "All Levels" button from the menu, it load the scene with all the levels, but when you click for example on the button Level 1 it load the level 1 scene but you can't do anything in it, i can't move the player for example. It like if the scene is not started. What is the problem? I hope somebody can help me with this problem because i don't know a solution.

    Thanks!
     

    Attached Files:

  2. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    You'll need to show some code (in [ CODE] [ /CODE] blocks (remove the spaces)) for us to help - with the info you've given there is almost no chance of us having any idea what could be wrong.
     
  3. Barft

    Barft

    Joined:
    Apr 9, 2015
    Posts:
    84
    The menu activator script is:

    public GameObject pauseButton, pausepanel;

    public void OnPause() {
    pausepanel.SetActive (true);
    pauseButton.SetActive (false);
    Time.timeScale = 0;
    }

    public void OnUnPause () {
    Time.timeScale = 1;
    pausepanel.SetActive (false);
    pauseButton.SetActive (true);
    }

    its a little hard to explain but, this script is added to the menu canvas.

    And the script to open the All level scene is:

    public void ChangeToScene (int sceneToChangeTo) {
    Application.LoadLevel (sceneToChangeTo);
    }

    And the level buttons of the All levels scene is the same as here bove.
     
  4. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    In [ CODE] [ /CODE] blocks (remove the spaces)) with proper formatting/indentation.

    Please!!

    Not 100% sure but I expect your issue is:

    Code (csharp):
    1. Time.timeScale = 0;
    For a test change that to Time.timeScale = 0.0001;

    see if things improve (that is not a valid solution I propose, just a test to see if things start working).
     
  5. Barft

    Barft

    Joined:
    Apr 9, 2015
    Posts:
    84
    it doesn't work
     
  6. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    As you are running this in Unity Editor, you should not, but remember to add all the scenes to your build properties. Besides that, where does your code know, what Application.LoadLevel (sceneToChangeTo); needs to do? So you are saying, LoadLevel(1) for example, but what is 1?
     
  7. Barft

    Barft

    Joined:
    Apr 9, 2015
    Posts:
    84
    ok, guys. I explain it hopely simple to you. I have made a test project, i have made a button in it and it opened a canvas,

    I added a script to the canvas:



    ok, the button that opened the canvas have i added to pauseButton, and i have made a panel in the canvas with 2 buttons. I added the panel to the pausepanel. And i gave the button that open the canvas a OnClick function, and added the canvas with the panel in it. So if you click the button (pauseButton) it open the canvas with the panel and the 2 buttons in it. The first button is "back", i gave it also an Onclick function, and added the canvas. The second button is called "All Levels". If you click it, it open a new scene with all buttons. To open the new scene i have made a empty game object and give it a script:

    Code (CSharp):
    1.  
    2. public void ChangeToScene (int sceneToChangeTo) {
    3.         Application.LoadLevel (sceneToChangeTo);
    4.     }
    5.  
    in the unity inspector you can fill in a number of the buildscene list, so it open the scene. So i gave the "All Levels" button a onclick fuction and added the empty game object to it. I hope everything is still clear for you. So far everything work fine. So i have made the All level scene with all the button of the levels. You got a button than called "Level 1", than "Level 2" etc. So i have added the same solution here above to open a new scene. So i have made a new scene that is going to be open by the button "Level 1" if you click it. The scene got a timer that is added to the main Camera, the script is this:

    Code (CSharp):
    1.  
    2. float timeRemaining = 5;
    3.         public Font f;
    4.         public GUIStyle henk;
    5.    
    6.    
    7.    
    8.         // Use this for initialization
    9.         void Start () {
    10.        
    11.         }
    12.    
    13.         // Update is called once per frame
    14.         void Update () {
    15.             timeRemaining -= Time.deltaTime;
    16.         }
    17.    
    18.         void OnGUI () {
    19.             if (timeRemaining > 0) {
    20.                 GUI.contentColor = Color.black;
    21.                 GUI.skin.font = f;
    22.                 GUI.Label(new Rect(10,10,50,20), "Time:" + timeRemaining.ToString(" 0"), henk);
    23.             }
    24.             else {
    25.                 Application.LoadLevel("failedLevel1");
    26.             }
    27.         }
    28.  
    29. so its countdown and than it loads a new scene thats said you failed. (Nothing important), it has also a button that open the pause menu, exactly the same way as above.
    30.  
    31. but, it has also a player, namely a ball, the script of the ball is this:
    32.  
    33.     // Using same speed reference in both, desktop and other devices
    34.     public float speed = 1000;
    35.  
    36.  
    37.  
    38.  
    39.     void Main ()
    40.     {
    41.         // Preventing mobile devices going in to sleep mode
    42.         //(actual problem if only accelerometer input is used)
    43.         Screen.sleepTimeout = SleepTimeout.NeverSleep;
    44.     }
    45.  
    46.     void Update()
    47.     {
    48.    
    49.         if (SystemInfo.deviceType == DeviceType.Desktop)
    50.         {
    51.             // Exit condition for Desktop devices
    52.             if (Input.GetKey("escape"))
    53.                 Application.Quit();
    54.         }
    55.         else
    56.         {
    57.             // Exit condition for mobile devices
    58.             if (Input.GetKeyDown(KeyCode.Escape))
    59.                 Application.Quit();        
    60.         }
    61.    
    62.    
    63.    
    64.     }
    65.  
    66.  
    67.     void FixedUpdate ()
    68.     {
    69.         if (SystemInfo.deviceType == DeviceType.Desktop)
    70.         {
    71.             // Player movement in desktop devices
    72.        
    73.             // Definition of force vector X and Y components
    74.             float moveHorizontal = Input.GetAxis("Horizontal");
    75.             float moveVertical = Input.GetAxis("Vertical");
    76.             // Building of force vector
    77.             Vector3 movement = new Vector3 (moveHorizontal,0.0f,moveVertical);
    78.             // Adding force to rigidbody
    79.             GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
    80.        
    81.        
    82.        
    83.         }
    84.         else
    85.         {
    86.             // Player movement in mobile devices
    87.        
    88.             // Building of force vector
    89.             Vector3 movement = new Vector3 (Input.acceleration.x, 0.0f, Input.acceleration.y);
    90.             // Adding force to rigidbody
    91.             GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
    92.         }
    93.    
    94.    
    95.     }
    96.  
    So if you clicked on the Level 1 button in the all leves scene it opened the scene but the timer dont count down and you cant play with the player. But the stranged thing is that i can click the button and the menu works just fine.

    I really hope that you guys can help me with this.

    I have also made a test project and i have apply the same things here above but level 1 has not a player or timer or button and it works perfect.
     
    Last edited: Jun 1, 2015
  8. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    could you please edit your post and put the code in code tags? It is barely readable with a plain text there...
     
  9. Barft

    Barft

    Joined:
    Apr 9, 2015
    Posts:
    84
    o ok