Search Unity

Levels

Discussion in 'Scripting' started by Airmand, Jul 25, 2011.

  1. Airmand

    Airmand

    Joined:
    Jan 27, 2011
    Posts:
    139
    I currently have my game setup so that everytime you die you start back at level 1. But im wanting to change it so that when you die you start back at the level you were just on. Any tips on how i could go about making that work?
     
  2. kjartanith

    kjartanith

    Joined:
    Jul 22, 2011
    Posts:
    25
    if("the var you use for dying")
    {
    //load level
    Application.LoadLevel(1);
    }

    i think this is what you need
     
  3. Airmand

    Airmand

    Joined:
    Jan 27, 2011
    Posts:
    139
    Thanks for posting but thats basically what I already have. I already have it set to load level 1. But what I'm looking for is for it to load the level that you were just on.
     
  4. RicheyMB

    RicheyMB

    Joined:
    Jul 20, 2009
    Posts:
    111
    You need to do something along the lines of creating a current level variable then adding some logic to your game to load the correct level acording to that variable.

    You'll then need to save that variable so it persists between games.

    You can use PlayerPrefs to save variables to the registry or save them to a file. It all depends on how complex you need to make things.
     
  5. Airmand

    Airmand

    Joined:
    Jan 27, 2011
    Posts:
    139
    Thats basically what i figured i would need to do. I just cant find anything in the scripting reference that I can use in the script to make the game know what level is current
     
  6. RicheyMB

    RicheyMB

    Joined:
    Jul 20, 2009
    Posts:
    111
    What language are you scripting in?

    I usually have a static class called 'GameState' that contains all the information about the current game and has a save and load method in.
     
  7. Airmand

    Airmand

    Joined:
    Jan 27, 2011
    Posts:
    139
    Ah. Im scripting in unity script. But have only been scripting for 6 months or so am still learning. I still havent really understood how to use arrays, enums and such and im not sure what exactly a class is.