-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameBaseController.cs
58 lines (44 loc) · 1.1 KB
/
GameBaseController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameBaseController : MonoBehaviour {
// internal
private bool m_gameOver = false;
private bool m_gameStarted = false;
protected bool m_gameWon = false; // consuming class sets this if game won
protected float timer; // Countdown timer
private float gameTime = 30f; // 30 seconds
//
// components
protected AudioSource m_audioSource;
//
// Start is called before the first frame update
protected virtual void Start() {
timer = gameTime;
m_audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
protected virtual void Update() {
if (!m_gameStarted) {
return;
}
if(m_gameStarted) {
timer -= Time.deltaTime;
}
if (timer <= 0f) {
EndGame();
}
}
protected virtual void StartGame() {
}
protected virtual void SetupPreGame() {
m_gameStarted = true;
m_gameWon = false;
m_gameOver = false;
StartGame();
}
protected virtual void EndGame() {
m_gameOver = true;
m_gameStarted = false;
}
}