Daily Progress — Preparing the Skeleton Enemy To GetHit
All right! We’re going to start interacting with enemies now! But in order for that to happen, they have to have BoxCollider2Ds too, so we’ll put one on our skeleton enemy and set the collider to trigger.
The skeleton has a hit animation we’ll have to implement, Just like before, we’ll create a new Animation clip, drag the frames in, and set it to a decent speed at around 25 samples.
One thing is this animation should only be played once, so we need to turn looping off, so select the animation and turn it off in the loop-time option.
Creating the logic in the Mecanim Animator window is easy, we want our skeleton to play the hit animation at any time. If he’s standing idle, or moving, if he’s hit, we want skelly to react! We’ll do that by creating a new trigger called Hit, and then make a transition from ‘any state’ to hit using the hit trigger as its condition. Of course there will be no exit time or duration. We want things to instantly happen!
The next issue we’ll get into next time is when should we trigger the hit animation? Naturally when its hit by the player so in the players attack function, if it hits something and recognizes it as an enemy, it will have to send a message to the enemys saying “Hey, call your damage function!” and we’ll do that with an IDamagable interface. What’s that? Stay tuned!