-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleController.cs
140 lines (129 loc) · 4.61 KB
/
BattleController.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BattleController : MonoBehaviour
{
public bool paused = false;
public GameObject upgradeMenu;
public GameObject soundtrack;
public GameObject player;
public GameObject factoryStage;
public GameObject mausoleumStage;
public GameObject palaceStage;
public GameObject enemySpawner;
public void Pause(){
paused = true;
Time.timeScale = 0;
// Find Player tagged objects and set paused to true
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject player in players)
{
player.GetComponent<Player>().paused = true;
}
// Find Enemy tagged objects and set paused to true
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject enemy in enemies)
{
enemy.GetComponent<Enemy>().paused = true;
}
// Find Attack tagged objects and set paused to true
GameObject[] attacks = GameObject.FindGameObjectsWithTag("Attack");
foreach (GameObject attack in attacks)
{
// if attack has component AttackMove
if (attack.GetComponent<AttackMove>())
{
attack.GetComponent<AttackMove>().paused = true;
}
}
}
public void Unpause(){
paused = false;
Time.timeScale = 1;
// Find Player tagged objects and set paused to false
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject player in players)
{
player.GetComponent<Player>().paused = false;
}
// Find Enemy tagged objects and set paused to false
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject enemy in enemies)
{
enemy.GetComponent<Enemy>().paused = false;
}
// Find Attack tagged objects and set paused to false
GameObject[] attacks = GameObject.FindGameObjectsWithTag("Attack");
foreach (GameObject attack in attacks)
{
// if attack has component AttackMove
if (attack.GetComponent<AttackMove>())
{
attack.GetComponent<AttackMove>().paused = false;
}
}
}
public void PauseUnpause()
{
if (!paused)
{
Pause();
}
else
{
Unpause();
}
}
public void UpgradeMenu()
{
Pause();
upgradeMenu.SetActive(true);
upgradeMenu.GetComponent<UpgradeMenu>().RandomSelect();
}
public virtual void OnStart()
{
// Data.beatenLevel1 = true; // TODO remove this
// Data.beatenLevel2 = true; // TODO remove this
// SceneController.input = "3"; // TODO remove this
if (SceneController.input == "1"){
factoryStage.SetActive(true);
enemySpawner.GetComponent<EnemySpawner>().level = 1;
soundtrack.GetComponent<AudioSource>().clip = Resources.Load<AudioClip>("Audio/FACTORY_THEME_FINAL");
soundtrack.GetComponent<AudioSource>().Play();
}
else if (SceneController.input == "2"){
mausoleumStage.SetActive(true);
enemySpawner.GetComponent<EnemySpawner>().level = 2;
soundtrack.GetComponent<AudioSource>().clip = Resources.Load<AudioClip>("Audio/MAUSOLEUM_THEME_FINAL");
soundtrack.GetComponent<AudioSource>().Play();
}
else if (SceneController.input == "3"){
palaceStage.SetActive(true);
enemySpawner.GetComponent<EnemySpawner>().level = 3;
soundtrack.GetComponent<AudioSource>().clip = Resources.Load<AudioClip>("Audio/PALACE_THEME_FINAL");
soundtrack.GetComponent<AudioSource>().Play();
}
else{
palaceStage.SetActive(true);
enemySpawner.GetComponent<EnemySpawner>().level = 4;
soundtrack.GetComponent<AudioSource>().clip = Resources.Load<AudioClip>("Audio/PALACE_THEME_FINAL");
soundtrack.GetComponent<AudioSource>().Play();
}
enemySpawner.GetComponent<EnemySpawner>().Begin();
// Unpause();
// UpgradeMenu();
Pause();
upgradeMenu.SetActive(true);
upgradeMenu.GetComponent<UpgradeMenu>().RandomSelectWeapons();
}
void Start()
{
OnStart();
}
void Update(){
// TODO remove for webgl build
if (Input.GetKeyDown(KeyCode.Escape)){
SceneController.loadScene("MainMenu");
}
}
}