-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerScript.cs
57 lines (46 loc) · 1.2 KB
/
PlayerScript.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
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerScript : MonoBehaviour
{
private int health;
public Text healthText;
public Text ballsText;
private int balls = 5;
public AudioClip collect;
void Start()
{
health = 3;
}
// Update is called once per frame
void Update()
{
ShowHealth();
ShowBalls();
}
void OnCollisionEnter(Collision coll) {
Debug.Log("Collision");
if (coll.gameObject.tag == "Enemy") {
health--;
}
if (health == 0) {
SceneManager.LoadScene("GameScene");
}
if (coll.gameObject.tag == "Ball") {
GetComponent<AudioSource>().PlayOneShot(collect, 1);
balls--;
Destroy(coll.gameObject);
}
if (balls == 0) {
SceneManager.LoadScene("GameScene");
}
}
public void ShowHealth() {
string message = health.ToString();
healthText.text = message;
}
public void ShowBalls() {
string message = balls.ToString();
ballsText.text = message;
}
}