2025-01-15 16:04:20 -05:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(Animator))]
|
|
|
|
|
public class AnimationPlayer : MonoBehaviour
|
|
|
|
|
{
|
2025-03-08 13:33:19 -05:00
|
|
|
public enum AnimationState { Idle, Run, Jump, Walk };
|
2025-01-15 16:55:07 -05:00
|
|
|
public AnimationState state;
|
|
|
|
|
public bool backwards;
|
2025-02-09 17:18:51 -05:00
|
|
|
public bool block = false;
|
2025-01-15 16:04:20 -05:00
|
|
|
public AnimationClip clip;
|
|
|
|
|
private Animator animator;
|
|
|
|
|
|
2025-03-28 17:39:07 -04:00
|
|
|
private void Start() // Plays the specified animation clip
|
2025-01-15 16:04:20 -05:00
|
|
|
{
|
|
|
|
|
animator = GetComponent<Animator>();
|
|
|
|
|
animator.Play(clip.name);
|
|
|
|
|
}
|
2025-01-15 16:55:07 -05:00
|
|
|
|
2025-03-28 17:39:07 -04:00
|
|
|
private void LateUpdate() // Updates the animation state
|
2025-01-15 16:55:07 -05:00
|
|
|
{
|
|
|
|
|
animator.SetInteger("state", (int)state);
|
|
|
|
|
transform.localScale = new Vector3(Mathf.Sign(backwards ? -1 : 1) * Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
|
2025-02-09 17:18:51 -05:00
|
|
|
animator.SetBool("block", block);
|
2025-01-15 16:55:07 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-28 17:39:07 -04:00
|
|
|
public void SetState(AnimationState state) // Sets the animation state
|
2025-01-15 16:55:07 -05:00
|
|
|
{
|
|
|
|
|
this.state = state;
|
|
|
|
|
}
|
2025-01-17 12:57:43 -05:00
|
|
|
|
2025-03-28 17:39:07 -04:00
|
|
|
public void Punch() // Triggers punch animation
|
2025-01-17 12:57:43 -05:00
|
|
|
{
|
|
|
|
|
animator.SetTrigger("punch");
|
|
|
|
|
}
|
2025-01-15 16:04:20 -05:00
|
|
|
}
|