Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Application.LoadLevel DONT WORK:.

Discussion in 'Editor & General Support' started by EdgarCarrera, Jun 14, 2014.

  1. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    Button New Game Dont Work. WHY Dont load the Map Level 1.

    My Script.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MainMenu : MonoBehaviour {
    5.     public GUISkin skin;
    6.  
    7.     void OnGUI()
    8.     {
    9.         GUI.skin = skin;
    10.         GUI.Label (new Rect(10,10, 400,75), "Go Home");
    11.         if (PlayerPrefs.GetInt("Level Completed") > 0)
    12.         {
    13.             if (GUI.Button(new Rect(10,100,100,45), "Continue"))
    14.             {
    15.                 Application.LoadLevel(PlayerPrefs.GetInt("Level Completed"));
    16.             }
    17.         }
    18.         if (GUI.Button(new Rect(10,155,100,45), "New Game"))
    19.         {
    20.             PlayerPrefs.SetInt("Level Completed", 0);
    21.             Application.LoadLevel(0);
    22.         }
    23.         if (GUI.Button(new Rect(10,210,100,45), "Quit"))
    24.         {
    25.             Application.Quit ();
    26.         }
    27.  
    28.     }
    29. }
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Looks like it's loading level 0. Read the docs, it's not a buggy function.
     
  3. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    My guess is that level 0 in your case is the one containing the New Game button, in which case in order to load the first level, you will have to call Application.LoadLevel(1);
     
  4. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    i have added already in the build setting.
     
  5. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Well, your continue button gets displayed if the "Level Completed" player pref is greater than one. How does this player pref get set? Also, you say your "new game" button doesn't work, and it doesn't load level one. But the code, line 21, loads level 0. Is it supposed to load level 0, or 1?