Player now turns to their move direction
This commit is contained in:
parent
f7258e4668
commit
ebf4b0e982
|
@ -5,11 +5,30 @@ 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");
|
||||
|
|
Loading…
Reference in New Issue