Batch 1 - Scripts
This commit is contained in:
47
Assets/New Lowpoly Models/Scripts/Player/CombatAnimations.cs
Normal file
47
Assets/New Lowpoly Models/Scripts/Player/CombatAnimations.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user