Game Development Reference
In-Depth Information
Listing 5-4. Changing PlayerController.cs to Handle Cash Collection
01 //------------------------------------------------
02 using UnityEngine;
03 using System.Collections;
04 using System.Collections.Generic;
05 //------------------------------------------------
06 public class PlayerController : MonoBehaviour
07 {
08 //------------------------------------------------
09 //Amount of cash player should collect to complete level
10 public float CashTotal = 1400.0f;
11
12 //Amount of cash for this player
13 private float cash = 0.0f;
14
15 //Reference to transform
16 private Transform ThisTransform = null;
17
18 //------------------------------------------------
19 //Called when object is created
20 void Start()
21 {
22 //Get First person capsule and make non-visible
23 MeshRenderer Capsule = GetComponentInChildren<MeshRenderer>();
24 Capsule.enabled = false;
25
26 //Get cached transform
27 ThisTransform = transform;
28 }
29 //------------------------------------------------
30 //Accessors to set and get cash
31 public float Cash
32 {
33 //Return cash value
34 get{return cash;}
35
36 //Set cash and validate, if required
37 set
38 {
39 //Set cash
40 cash = value;
41
42 //Check collection limit - post notification if limit reached
43 if(cash >= CashTotal)
44 GameManager.Notifications.PostNotification(this, "CashCollected");
45 }
46 }
47 //------------------------------------------------
48 }
Search WWH ::




Custom Search