PadPlay

Pause when a phone leaves

When a player turns the phone's screen off or goes to the home screen, pause the game under a pause screen and go on when they are back.

On the Host's GameObject: Add Component → PadPlay → Away Pause

Add the line below to scripts that read input directly (Time.timeScale does not stop them)

using PadPlay;
using UnityEngine;

public class Shooter : MonoBehaviour
{
    [SerializeField] PadPlayHost host;

    void Update()
    {
        if (PadPlayAwayPause.IsAnyPaused)
            return;   // the pause screen is up: no shots, no timers

        PadPlayPad pad = host.GetPad(0);
        if (pad != null && pad.buttonSouth.wasPressedThisFrame)
            Shoot();
    }

    void Shoot()
    {
        // ...
    }
}

Press Play, connect a phone, then turn its screen off or go to the home screen: the game blurs under Paused and stops. Back in the app, it goes away and the game goes on. Without a phone, use Leave app and Back to the game on a Virtual Phone.