Auto-pause the game when losing focus

This script auto-pauses the game when the window that its running in loses focus. To use it, attach it as a component to a GameObject in your scenes.

PauseFocus.cs using UnityEngine; using System.Collections; using AC; public class PauseFocus : MonoBehaviour {     private bool isPaused; private void OnApplicationFocus (bool hasFocus) {         if (KickStarter.stateHandler.gameState == GameState.Paused) {             return; }         IsPaused = !hasFocus; }     private void OnApplicationPause (bool pauseStatus) {         if (KickStarter.stateHandler.gameState == GameState.Paused) {             return; }         IsPaused = pauseStatus; }     private bool IsPaused {         set {             if (isPaused != value) {                 isPaused = value; if (isPaused) {                     KickStarter.sceneSettings.PauseGame ; }                 else {                     KickStarter.sceneSettings.UnpauseGame (1f); }             }          }      }  }