-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
66 lines (51 loc) · 1.33 KB
/
Player.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
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
[System.Serializable]
public class PlayerStats
{
public int maxHealth = 100;
private int _curHealth;
public int curHealth
{
get { return _curHealth;}
set { _curHealth = Mathf.Clamp(value, 0, maxHealth); }
}
public void Init()
{
curHealth = maxHealth;
}
}
public PlayerStats stats = new PlayerStats();
public int fallBoundary = -20;
[SerializeField]
private StatusIndicator statusIndicator;
void Start()
{
stats.Init();
if (statusIndicator == null)
{
Debug.LogError("No status indicator reference on Player");
}
else
{
statusIndicator.SetHealth(stats.curHealth, stats.maxHealth);
}
}
void Update()
{
if (transform.position.y <= fallBoundary)
{
DamagePlayer(9999999);
}
}
public void DamagePlayer(int damage)
{
stats.curHealth -= damage;
if (stats.curHealth <= 0)
{
GameMaster.KillPlayer(this);
}
statusIndicator.SetHealth(stats.curHealth, stats.maxHealth);
}
}