-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtower_control.cs
91 lines (81 loc) · 2.42 KB
/
tower_control.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
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class tower_control : MonoBehaviour {
private bool shouldRotateClockwise = false;
private bool shouldRotateCounterClockwise = false;
private int health = 100;
public int score = 0;
private Text healthbar;
private Text finalScore;
public EnemyForward.EnemyType killedBy;
public Sprite anteater;
public Sprite cat;
public Sprite cage;
// Use this for initialization
void Start () {
healthbar = GameObject.Find("health").GetComponent<Text>();
finalScore = GameObject.Find("finalScore").GetComponent<Text>();
GameObject.Find("Start").GetComponent<Image>().enabled = true;
}
// Update is called once per frame
void Update ()
{
if (shouldRotateClockwise) {
float angle = -5;
transform.RotateAround(transform.position, transform.up, angle);
}
if (shouldRotateCounterClockwise) {
float angle = 5;
transform.RotateAround(transform.position, transform.up, angle);
}
}
public void Clockwise () {
shouldRotateClockwise = true;
}
public void ClockwiseStop () {
shouldRotateClockwise = false;
}
public void CounterClockwise () {
shouldRotateCounterClockwise = true;
}
public void CounterClockwiseStop () {
shouldRotateCounterClockwise = false;
}
bool alive = true;
void OnCollisionEnter (Collision collision)
{
if (collision.gameObject.tag == "enemy") {
health -= 10;
Destroy (collision.gameObject);
if (health < 1 && alive) {
alive = false;
killedBy = collision.gameObject.GetComponent<EnemyForward> ().type;
if (killedBy == EnemyForward.EnemyType.anteater) {
GameObject.Find("End").GetComponent<Image>().sprite = anteater;
}
else if (killedBy == EnemyForward.EnemyType.cat) {
GameObject.Find("End").GetComponent<Image>().sprite = cat;
}
else if (killedBy == EnemyForward.EnemyType.cage) {
GameObject.Find("End").GetComponent<Image>().sprite = cage;
}
finalScore.text = "Score " + score;
finalScore.enabled = true;
GameOver();
}
healthbar.text = "Life " + health + " Score " + score;
}
}
public void GameOver (){
GameObject.Find("End").GetComponent<Image>().enabled = true;
}
public void RestartGame (){
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void StartGame() {
GameObject.Find("Start").GetComponent<Image>().enabled = false;
GameController.StartEnemies();
}
}