Game Development Reference
In-Depth Information
Listing 7-4. Amending Enemy_Drone to Work with PingPongSpriteColor
01 using UnityEngine;
02 using System.Collections;
03
04 public class Enemy_Drone : Enemy
05 {
06 //------------------------------------------------
07 //Event called when damaged by an attack
08 public void Damage(int Damage = 0)
09 {
10 //Reduce health
11 Health -= Damage;
12
13 //Play damage animation
14 gameObject.SendMessage("PlayColorAnimation",0,SendMessageOptions.
DontRequireReceiver);
15
16 //Check if dead
17 if(Health <= 0)
18 {
19 //Send enemy destroyed notification
20 GameManager.Notifications.PostNotification(this, "EnemyDestroyed");
21
22 //Remove object from scene
23 DestroyImmediate(gameObject);
24
25 //Clean up old listeners
26 GameManager.Notifications.RemoveRedundancies();
27 }
28 }
29 //------------------------------------------------
30 }
Let's see this code in action in the Unity Editor, as shown in Figure 7-11 . The result: our Enemy
now responds not only to attacks in terms of health reduction, but the gamer can actually see an
indication that damage has been taken. Splendid work. Let's move on!
 
Search WWH ::




Custom Search