fgm24/Assets/Scripts/Player/PlayerAnimationHandler.cs

53 lines
999 B
C#
Raw Normal View History

2024-02-03 11:42:50 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAnimationHandler : MonoBehaviour
{
Animator animator;
SpriteRenderer sp;
Vector3 prevPos;
2024-02-03 11:42:50 +01:00
void Start()
{
animator = GetComponentInChildren<Animator>();
sp = GetComponentInChildren<SpriteRenderer>();
}
2024-02-03 11:42:50 +01:00
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;
2024-02-03 21:35:06 +01:00
}
2024-02-03 13:07:46 +01:00
public void Idle()
2024-02-03 11:42:50 +01:00
{
2024-02-03 13:07:46 +01:00
animator.SetTrigger("Idle");
2024-02-03 11:42:50 +01:00
}
2024-02-03 13:07:46 +01:00
public void Run()
2024-02-03 11:42:50 +01:00
{
2024-02-03 13:07:46 +01:00
animator.SetTrigger("Run");
2024-02-03 11:42:50 +01:00
}
2024-02-03 13:07:46 +01:00
public void Swing()
2024-02-03 11:42:50 +01:00
{
2024-02-03 13:07:46 +01:00
animator.SetTrigger("Swing");
2024-02-03 11:42:50 +01:00
}
2024-02-03 13:07:46 +01:00
public void Mop()
2024-02-03 11:42:50 +01:00
{
2024-02-03 13:07:46 +01:00
animator.SetTrigger("Mop");
2024-02-03 12:21:41 +01:00
}
2024-02-03 13:07:46 +01:00
public void RunMop()
2024-02-03 12:21:41 +01:00
{
2024-02-03 13:07:46 +01:00
animator.SetTrigger("RunMop");
2024-02-03 11:42:50 +01:00
}
}