How to check my current scene and when press back button(in mobile) ,go to lower scene?

Hi all,
Here i have two scenes , Scene-0(menu) and Scene-1(game scene).
When am in game scene and press back button in mobile i have to go in Scene-0(menu),
and again when i press back button the game should be Quit.

Please give me some code lines to go with this.I know this is very small Question.

You should not check your current scene to decide what new scene to load, just write a script that you point to from the button click event to load a scene by id or name.

Relevant sources:

Hi, Actually i dont want any extra UI in my scene/canvas.
I want just use back button of the mobile.
Am using C#
Thx.

Hey babji3,

Unity allows to check name of current scene using Application.loadedLevel which returns name of current scene,

Here is the code for what you want,

    void Update ()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
        {
            if(Application.loadedLevelName == "Game")
            {
                Application.LoadLevel("Menu");
            }
            else if(Application.loadedLevelName == "Menu")
            {
                Application.Quit();
            }
        }
    }

Also don’t forgot to write DontDestroyOnLoad(this.gameObject); in script the above code is written…

Thx khokhanu, I don’t know we can check by name itself. I’ll try this.