Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections; 3.
4. public class LivesManager : MonoBehaviour { 5.
6.
//Initial number of lives
7.
public int startLives = 3;
8.
9.
//internal counter
10.
int lives;
11.
12.
void Start () {
13.
//Enforce at least one life initially
14.
if(startLives > 0){
15.
lives = startLives;
16.
} else {
17.
lives = 1;
18.
}
19.
}
20.
21.
void Update () { 22.
23.
}
24.
25.
public void GiveLife(){
26.
lives++;
27.
SendMessage("OnLifeGained",
28.
lives,
//New number of lives
29.
SendMes-
sageOptions.DontRequireReceiver);
30.
}
31.
32.
public void TakeLife(){
33.
lives--;
34.
if(lives == 0){
35.
//Last live lost
Search WWH ::




Custom Search