fgm24/Assets/Scripts/Player/PlayerAnimationHandler.cs

53 lines
996 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAnimationHandler : MonoBehaviour
{
Animator animator;
SpriteRenderer sp;
Vector3 prevPos;
void Start()
{
animator = GetComponentInChildren<Animator>();
sp = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
if ((transform.position - prevPos).x > 0.1f)
{
sp.flipX = false;
}
else if ((transform.position - prevPos).x < -0.1f)
{
sp.flipX = true;
}
prevPos = transform.position;
}
public void Idle()
{
animator.SetTrigger("Idle");
}
public void Run()
{
animator.SetTrigger("Run");
}
public void Swing()
{
animator.SetTrigger("Swing");
}
public void Mop()
{
animator.SetTrigger("Mop");
}
public void RunMop()
{
animator.SetTrigger("RunMop");
}
}