fgm24/Assets/Scripts/Player/SpriteMovementFlipper.cs

29 lines
551 B
C#

using UnityEngine;
public class SpriteMovementFlipper : MonoBehaviour
{
[SerializeField] private bool invert = false;
SpriteRenderer sp;
Vector3 prevPos;
void Start()
{
sp = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
if ((transform.position - prevPos).x > 0.1f)
{
sp.flipX = invert;
}
else if ((transform.position - prevPos).x < -0.1f)
{
sp.flipX = !invert;
}
prevPos = transform.position;
}
}