fgm24/Assets/Scripts/Player/SpriteMovementFlipper.cs

27 lines
496 B
C#

using UnityEngine;
public class SpriteMovementFlipper : MonoBehaviour
{
SpriteRenderer sp;
Vector3 prevPos;
void Start()
{
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;
}
}