|
|
@ -12,11 +12,19 @@ public class PlayerController : MonoBehaviour { |
|
|
|
|
|
|
|
public GameObject waveRing; |
|
|
|
|
|
|
|
public int life = 3; |
|
|
|
public float lastDamageTime = 0; |
|
|
|
|
|
|
|
public static PlayerController instance; |
|
|
|
|
|
|
|
public GameObject[] lifeHearts; |
|
|
|
|
|
|
|
void Start() { |
|
|
|
|
|
|
|
NotificationServer.register("show GameUI", showGameUI); |
|
|
|
NotificationServer.register("hide GameUI", hideGameUI); |
|
|
|
|
|
|
|
instance = this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -48,6 +56,23 @@ public class PlayerController : MonoBehaviour { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void setLife(int life) { |
|
|
|
for (int i = 0; i < lifeHearts.Length; i++) { |
|
|
|
lifeHearts[i].SetActive((i < life)); |
|
|
|
} |
|
|
|
this.life = life; |
|
|
|
} |
|
|
|
|
|
|
|
public void takeOneDamage() { |
|
|
|
if (Time.time > lastDamageTime + 2 && life > 0) { |
|
|
|
setLife(life - 1); |
|
|
|
lastDamageTime = Time.time; |
|
|
|
if (life == 0) |
|
|
|
NotificationServer.notify("show GameOverPanel"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void showGameUI() { |
|
|
|
Debug.Log("UI open"); |
|
|
|
isLocked = false; |
|
|
|