Forum rules - please read before posting.

Pause game if app loses focus

edited November 2021 in Technical Q&A

Hello,

Is there a setting in AC for it to automatically pause should the game window not be the focus (i.e. the player alt-tabs into some other app)?

Basically I want it so if focus is lost, the game pauses activating the pause menu, and then when the player returns they have to resume as normal.

Comments

  • You can rely on Unity's OnApplicationFocus function, triggered when this occurs, to have AC bring up the pause menu.

    Best to also check if AC is already paused, so that it doesn't turn on the Pause menu again.

    Something like this inside a MonoBehaviour should do it:

    private void OnApplicationFocus (bool focus)
    {
        if (!focus && !KickStarter.stateHandler.IsPaused ())
        {
            AC.PlayerMenus.GetMenuWithName ("Pause").TurnOn ();
        }
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.