Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Created July 16, 2021 00:36
Show Gist options
  • Select an option

  • Save kurtdekker/b7bf4810d698a491c0e8bb368ba1c599 to your computer and use it in GitHub Desktop.

Select an option

Save kurtdekker/b7bf4810d698a491c0e8bb368ba1c599 to your computer and use it in GitHub Desktop.
A way to easily pause the action while dialogs are up
using UnityEngine;
// @kurtdekker
//
// For stopping your game during instantiated / enabled dialogs.
//
// To use: put this script on things that you want to
// stop your game action when they appear, like dialogs.
//
// You only need one instance of this script per dialog.
//
// Then in your actual game move code, check it like so:
//
// if (StopTheAction.IsPaused())
// {
// return; // early return; we are paused
// }
//
// or:
// if (StopTheAction.IsRunning())
// {
// DoPlayerMovement();
// }
public class StopTheAction : MonoBehaviour
{
static int stopCount;
public static bool IsPaused()
{
return stopCount > 0;
}
public static bool IsRunning()
{
return stopCount <= 0;
}
void OnEnable()
{
stopCount++;
}
void OnDisable()
{
stopCount--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment