Files
Crash-Course/Assets/Scripts/AnimationPlayer.cs

40 lines
896 B
C#
Raw Normal View History

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 };
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;
private void Start()
{
animator = GetComponent<Animator>();
animator.Play(clip.name);
}
private void LateUpdate()
{
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);
}
public void SetState(AnimationState state)
{
this.state = state;
}
2025-01-17 12:57:43 -05:00
public void Punch()
{
animator.SetTrigger("punch");
}
2025-01-15 16:04:20 -05:00
}