Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections; 3.
4. public class PlayerHealth : MonoBehaviour { 5.
6.
//Health amount at the beginning
7.
public int initialHealth = 100;
8.
9.
//Max health limit
10.
public int maxHealth = 100;
11.
12.
//Current health
13.
int health;
14.
15.
//Internaldeadflag
16.
bool dead = false;
17.
18.
void Start () {
19.
//Insure appropriate initial health
20.
health = Mathf.Min(initialHealth, maxHealth);
21.
//Player cannot start dead
22.
if(health < 0){
23.
health = 1;
24.
}
25.
}
26.
27.
void Update () {
28.
if(!dead){
29.
if(health <= 0){
30.
//Player died
31.
dead = true;
32.
33.
//Tell other scripts about player's death
34.
//and give them his final health
35.
SendMes-
sage("OnPlayerDeath",
Search WWH ::




Custom Search