/
PlayerCharacter.cs
51 lines (46 loc) · 986 Bytes
/
PlayerCharacter.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
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerCharacter : MonoBehaviour
{
void Awake()
{
Messenger<int>.AddListener(GameEvent.HEALTH_PACK,
heal);
}
void OnDestroy()
{
Messenger<int>.RemoveListener(GameEvent.HEALTH_PACK,
heal);
}
private int _health;
[SerializeField]
public Slider healthBar;
void Start()
{
_health = 100;
healthBar.value = _health;
}
public void Hurt(int damage)
{
if (_health > 0)
{
_health -= damage;
}
healthBar.value = _health;
Managers.Player.decreaseHealth(damage);
}
public void heal(int increase)
{
_health += increase;
healthBar.value = _health;
Managers.Player.IncreaseHealth(increase);
}
public void die()
{
if (_health == 0)
{
// Managers.Mission.LoadGame();
}
}
}