47 lines
1.0 KiB
C#
47 lines
1.0 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class CharacterCombat : MonoBehaviour, IDamageReceiver
|
|
{
|
|
private Animator animator;
|
|
|
|
void Awake()
|
|
{
|
|
animator = GetComponentInChildren<Animator>();
|
|
}
|
|
|
|
public void OnDamageTaken(string bodyPart)
|
|
{
|
|
switch (bodyPart)
|
|
{
|
|
case "Head":
|
|
animator.SetTrigger("HitHead");
|
|
break;
|
|
|
|
case "Body":
|
|
animator.SetTrigger("HitBody");
|
|
break;
|
|
|
|
case "Legs":
|
|
StartCoroutine(KnockdownRoutine());
|
|
break;
|
|
}
|
|
}
|
|
|
|
IEnumerator KnockdownRoutine()
|
|
{
|
|
// Step 1: play leg hit
|
|
animator.SetTrigger("HitLegs");
|
|
|
|
// wait for hit animation
|
|
yield return new WaitForSeconds(0.6f);
|
|
|
|
// Step 2: fall happens automatically via Exit Time
|
|
|
|
// stay on ground
|
|
yield return new WaitForSeconds(2f);
|
|
|
|
// Step 3: stand up
|
|
animator.SetTrigger("StandUp");
|
|
}
|
|
} |