Add hit animation

This commit is contained in:
henriquenakashima 2020-09-25 20:45:12 -04:00
parent 4d817ea88a
commit c31747bc19
11 changed files with 592 additions and 5 deletions

View file

@ -9,17 +9,24 @@ public class BattleParticipantSprite : MonoBehaviour
private BattlePlayerControls playerControls;
private BattleParticipant participant;
private RuntimeAnimatorController animatorController;
private bool removedFromBattle;
public void Init(BattlePlayerControls playerControls, BattleParticipant participant) {
public void Init(BattlePlayerControls playerControls, BattleParticipant participant,
Material hitEffectMaterial, RuntimeAnimatorController animatorController) {
this.playerControls = playerControls;
this.participant = participant;
this.animatorController = animatorController;
this.removedFromBattle = false;
this.GetComponent<SpriteRenderer>().material = hitEffectMaterial;
}
// Start is called before the first frame update
void Start() {
gameObject.AddComponent<BoxCollider2D>();
Animator animator = gameObject.AddComponent<Animator>();
animator.runtimeAnimatorController = this.animatorController;
}
// Update is called once per frame
@ -58,7 +65,7 @@ public class BattleParticipantSprite : MonoBehaviour
public void NotifyDeath(BattleParticipant deadParticipant) {
if (deadParticipant != this.participant) {
throw new System.InvalidOperationException(
"BattleParticipantSprite received NotifyDeath from another battle participant.");
"BattleParticipantSprite received NotifyDeath for another battle participant.");
}
if (!this.removedFromBattle) {
@ -69,4 +76,15 @@ public class BattleParticipantSprite : MonoBehaviour
this.removedFromBattle = true;
}
}
public void NotifyHit(BattleParticipant deadParticipant) {
if (deadParticipant != this.participant) {
throw new System.InvalidOperationException(
"BattleParticipantSprite received NotifyHit for another battle participant.");
}
if (!this.removedFromBattle) {
Animator animator = gameObject.GetComponent<Animator>();
animator.Play("Hit");
}
}
}