Add basic intro countdown and game states

This commit is contained in:
BuyMyMojo 2023-03-03 09:13:47 +11:00
parent 89e482d387
commit 15abaa80fa
10 changed files with 740 additions and 6 deletions

View file

@ -0,0 +1,84 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameStateManager : MonoBehaviour
{
public static GameStateManager Instace{ get; private set; }
public event EventHandler OnStateChanged;
private enum State
{
WaitingToStart,
StartingCountdown,
GamePlaying,
GameOver,
}
private State state;
// --- Timers ---
private float waitingToStartTimer = 1f;
private float countdownToStartTimer = 3f;
private float gamePlayTimer = 10f;
private void Awake()
{
state = State.WaitingToStart;
Instace = this;
}
private void Update()
{
switch (state)
{
case State.WaitingToStart:
waitingToStartTimer -= Time.deltaTime;
if (waitingToStartTimer < 0f)
{
state = State.StartingCountdown;
OnStateChanged?.Invoke(this, EventArgs.Empty);
}
break;
case State.StartingCountdown:
countdownToStartTimer -= Time.deltaTime;
if (countdownToStartTimer < 0f)
{
state = State.GamePlaying;
OnStateChanged?.Invoke(this, EventArgs.Empty);
}
break;
case State.GamePlaying:
gamePlayTimer -= Time.deltaTime;
if (gamePlayTimer < 0f)
{
state = State.GameOver;
OnStateChanged?.Invoke(this, EventArgs.Empty);
}
break;
case State.GameOver:
break;
}
Debug.Log(state);
}
public bool IsGamePlaying()
{
return state == State.GamePlaying;
}
public bool IsCountdownToStartActive()
{
return state == State.StartingCountdown;
}
public float GetCountdownToStartTimer()
{
return countdownToStartTimer;
}
}