Game programming patterns: Observer
gameObject.SendMessage("HitByLightning", SendMessageOptions.DontRequireReceiver);
Game programming patterns: Singleton Game programming patterns: Singleton
void Awake () { // If there is more than ONE instance of ScoreManager // disabled the old instance to avoid errors if(instance != null) { Debug.LogError("More than ONE ScoreManager instance in game! Disabling old one."); instance.gameObject.SetActive(false); } // Set instance to this so class can be used everywhere // Make sure there is only ONE ScoreManager in the game instance = this; }
ScoreManager.instance.AddScore(1);
Game programming patterns: State
switch (PlayerState) case State.Walking: { if (Input.down("Fire1")) PlayerState = State.Jumping; } case State.Jumping: { } case State.Hurting { }