OnSceneQuit

Hello everybody,

I just wanna know, if there is any function(event) which is called before the current scene is left.

Like OnSceneQuit()

when I use Application.LoadLevel, I need to abort running threads in other scripts, before leaving the scene.

I know that I can use global variables to do that, just wanna know if there is any built-in function.

OnDisable is sent to MonoBehaviours when they are disabled or destroyed - which happens when you change scenes and the object is not set to DontDestroyOnLoad. Another alternative is that you centralize your level loading code in one script and then do the cleanup before doing the level load:

public class SceneManager
{
    private void Cleanup ()
    {
        // Access and shut down the threads and perform other cleanup tasks
    }

    public static void Load (int index)
    {
        Cleanup ();
        Application.LoadLevel (index);
    }

    public static void Load (string name)
    {
        Cleanup ();
        Application.LoadLevel (name);
    }
}

// In any script needing to change scenes, you now do that via SceneManager.Load in stead of Application.LoadLevel.

Thanks for your reply !!