/
PlayerInfo.cs
70 lines (62 loc) · 1.87 KB
/
PlayerInfo.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerInfo : MonoBehaviour {
public GameObject TimerText, HpBar, GameOverText, StatusText, PauseButton;
public float timer = 10.0f;
public int HpCurrent = 1000;
public int HpMax = 1000;
public int damagetaken = 1;
public Spawner cancelSpawn;
private Text status_text;
Image healthbar;
void Awake()
{
status_text = StatusText.GetComponent<Text>();
healthbar = HpBar.GetComponent<Transform>().FindChild("HealthBar").GetComponent<Image>();
}
void Update ()
{
timer -= Time.deltaTime;
Text time_text = TimerText.GetComponent<Text>();
if(HpCurrent <= 0)
{
cancelSpawn.CancelInvoke();
status_text.text = "YOU DIED!";
GameOverText.SetActive(true);
PauseButton.SetActive(false);
}
else if (timer >= 0.0f)
{
time_text.text = timer.ToString("F1") + "'s";
}
else
{
cancelSpawn.CancelInvoke();
time_text.text = "0.0's";
status_text.text = "TIME OUT!";
GameOverText.SetActive(true);
PauseButton.SetActive(false);
}
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "MeteorS")
{
HpCurrent -= damagetaken;
healthbar.fillAmount = (float)HpCurrent / HpMax;
}
else if (col.gameObject.tag == "MeteorM")
{
HpCurrent -= (damagetaken * 2);
healthbar.fillAmount = (float)HpCurrent / HpMax;
}
else if (col.gameObject.tag == "MeteorB")
{
HpCurrent -= (damagetaken * 3);
healthbar.fillAmount = (float)HpCurrent / HpMax;
}
Destroy(col.gameObject);
}
}