Created
July 16, 2021 00:36
-
-
Save kurtdekker/b7bf4810d698a491c0e8bb368ba1c599 to your computer and use it in GitHub Desktop.
A way to easily pause the action while dialogs are up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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