fgm24/Assets/Scripts/Player/Other/SpriteMovementFlipper.cs

29 lines
603 B
C#
Raw Normal View History

using UnityEngine;
2024-02-04 05:40:23 +01:00
using UnityUtils;
public class SpriteMovementFlipper : MonoBehaviour
{
2024-02-04 05:40:23 +01:00
[SerializeField] Transform flipTrans;
[SerializeField] Rigidbody2D body;
2024-02-03 21:52:24 +01:00
SpriteRenderer sp;
Vector3 prevPos;
void Start()
{
sp = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
2024-02-04 05:40:23 +01:00
if (body.velocity.x > 0.1f)
{
2024-02-04 05:40:23 +01:00
flipTrans.localScale = flipTrans.localScale.With(x: 1f);
}
2024-02-04 05:40:23 +01:00
else if (body.velocity.x < -0.1f)
{
2024-02-04 05:40:23 +01:00
flipTrans.localScale = flipTrans.localScale.With(x: -1f);
}
}
}