-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlayerScript.cs
More file actions
49 lines (38 loc) · 1.08 KB
/
Copy pathPlayerScript.cs
File metadata and controls
49 lines (38 loc) · 1.08 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerScript : MonoBehaviour
{
public float maxHealth;
public float playerHealth;
public bool canBeDamaged;
public Text text; //This is for the HUD
// Start is called before the first frame update
void Start()
{
playerHealth = maxHealth;
text.text = "Health: " + playerHealth;
}
// Update is called once per frame
void Update()
{
if (playerHealth == 0)
{
//Do game over
}
}
public void loseHealth() // Activate after a collision. Can also make this an OnCollisionEnter here.
{
if (canBeDamaged)
// playerHealth = playerHealth - obstacle.Damage;
text.text = "Health: " + playerHealth;
StartCoroutine(mercyInvincibility());
}
IEnumerator mercyInvincibility()
{
canBeDamaged = false;
yield return new WaitForSeconds(.5f);
canBeDamaged = true;
}
}