Add basic intro countdown and game states
This commit is contained in:
parent
89e482d387
commit
15abaa80fa
10 changed files with 740 additions and 6 deletions
84
Assets/Scripts/GameStateManager.cs
Normal file
84
Assets/Scripts/GameStateManager.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue