Skip to content

Instantly share code, notes, and snippets.

@troy-lamerton
Created April 20, 2017 07:13
Show Gist options
  • Save troy-lamerton/6701c62763fb29723a750f78bab22163 to your computer and use it in GitHub Desktop.
Save troy-lamerton/6701c62763fb29723a750f78bab22163 to your computer and use it in GitHub Desktop.
Example of global state script in unity. Doesn't need to be attached to any object, just call its methods and read its properties.
using UnityEngine;
public class GlobalState {
// bool paused = false;
public static int goop = 80;
public static int waveNumber = 1;
public static bool paused = false;
public static void AddGoop (int amount) {
goop += amount;
}
public static bool ConsumeGoop (int amount) {
if (amount <= goop) {
goop -= amount;
return true;
}
else {
Debug.Log("Cant afford " + amount + " for that");
return false;
}
}
public static bool SetPaused (bool pause) {
paused = pause;
return paused;
}
public static void WavePlusPlus() {
waveNumber++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment