Game Development Reference
In-Depth Information
079 //Set cash and validate, if required
080 set
081 {
082 //Set cash
083 cash = value;
084
085 //Check collection limit - post notification if limit reached
086 if(cash >= CashTotal)
087 GameManager.Notifications.PostNotification(this, "CashCollected");
088 }
089 }
090 //------------------------------------------------
091 //Accessors to set and get health
092 public int Health
093 {
094 //Return health value
095 get{return health;}
096
097 //Set health and validate, if required
098 set
099 {
100 health = value;
101
102 //Playe Die functionality
103 if(health <= 0) gameObject.SendMessage("Die",SendMessageOptions.
DontRequireReceiver);
104 }
105 }
106 //------------------------------------------------
107 //Function to apply damage to the player
108 public IEnumerator ApplyDamage(int Amount = 0)
109 {
110 //Reduce health
111 Health -= Amount;
112
113 //Post damage notification
114 GameManager.Notifications.PostNotification(this, "PlayerDamaged");
115
116 //Show damage texture
117 ShowDamage = true;
118
119 //Wait for interval
120 yield return new WaitForSeconds(DamageInterval);
121
122 //Hide damage texture
123 ShowDamage = false;
124 }
125 //------------------------------------------------
126 //ON GUI Function to show texture
127 void OnGUI()
128 {
129 if(ShowDamage){GUI.DrawTexture(ScreenRect,DamageTexture);}
130 }
Search WWH ::




Custom Search