fgm24/Assets/Scripts/Player/SpriteMovementFlipper.cs

29 lines
551 B
C#
Raw Normal View History

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