Game Development Reference
In-Depth Information
scene, but the run animation never plays back during the move, and so the Enemy simply looks like
he's hovering or sliding around the level. Creepy! So let's change that now. To do this, we'll return to the
Enemy_Drone class and make use of the SendMessage functionality, coded earlier in Listing 7-6, where the
ChangeState function sends a change state message to the enemy object. We'll use this message to
initiate playback of the relevant animation (see the amended Enemy_Drone script in Listing 7-8).
Listing 7-8. Enemy_Drone.cs: Integrating with Navigation
01 //------------------------------------------------
02 using UnityEngine;
03 using System.Collections;
04 //------------------------------------------------
05 public class Enemy_Drone : Enemy
06 {
07 //------------------------------------------------
08 //Sprites for walk animation
09 public SpriteRenderer[] WalkSprites = null;
10
11 //Sprites for attack animation
12 public SpriteRenderer[] AttackSprites = null;
13
14 //Default Sprite (neutral state)
15 public SpriteRenderer DefaultSprite = null;
16
17 //------------------------------------------------
18 //Event called when damaged by an attack
19 public void Damage(int Damage = 0)
20 {
21 //Reduce health
22 Health -= Damage;
23
24 //Play damage animation
25 gameObject.SendMessage("PlayColorAnimation",0,SendMessageOptions.
DontRequireReceiver);
26
27 //Check if dead
28 if(Health <= 0)
29 {
30 //Send enemy destroyed notification
31 GameManager.Notifications.PostNotification(this, "EnemyDestroyed");
32
33 //Remove object from scene
34 DestroyImmediate(gameObject);
35
36 //Clean up old listeners
37 GameManager.Notifications.RemoveRedundancies();
38 }
39 }
 
Search WWH ::




Custom Search