Application.LoadLevel not Resetting

I have a simple button that’s intended to restart the level.

The player starts in the level “Arcade” and when dies, goes to “LocalHighScore” where it shows the scoreboard and he is given two options: quit or Again!.

The button for again is thus:

if (GUI.Button(Rect(Screen.width *.7,Screen.height * .6, 128,64),"Again !"))

It loads the level, but nothing is reset. If I had to manually reset every variable to it’s initial setting I’d never stop forgetting one or two. According to the reference everything is scrapped and rebuilt unless you use DontDestroyOnLoad–and I never have. For anything. I’m a little confused as to why this happens.

(The actual effect is after reloading the level the player can’t move, the timer stops, their health is negative, nothing spawns. Opening the menu is broken)

I guess you use static variables? Now you know why you should avoid static variables because they don’t belong to any object instance and therefore will never be reset. Work with objects and references instead of static stuff. The only other way is to (re)set them manually in a function.

If you don’t use static variables (but i guess you do) i have no idea what’s going wrong.

A good work around is to use a singleton pattern instead of static variables.

myClass : MonoBehaviour

private static myClass mInstance;
public static myClass Instance() {return mInstance;}

void Awake() 
    if(!mInstance) mInstance = this;

//All you variables go here. This will ensure there is only one type of an object at a 
//time, but will still destroy and clear out your variables in every scene
//To access the variables, in your other scripts you will say