fgm24/Assets/Scripts/Player/SpriteMovementFlipper.cs

29 lines
553 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()
{
2024-02-04 00:19:01 +01:00
if ((transform.position - prevPos).x > 0.05f)
{
2024-02-03 21:52:24 +01:00
sp.flipX = invert;
}
2024-02-04 00:19:01 +01:00
else if ((transform.position - prevPos).x < -0.05f)
{
2024-02-03 21:52:24 +01:00
sp.flipX = !invert;
}
prevPos = transform.position;
}
}