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

29 lines
603 B
C#

using UnityEngine;
using UnityUtils;
public class SpriteMovementFlipper : MonoBehaviour
{
[SerializeField] Transform flipTrans;
[SerializeField] Rigidbody2D body;
SpriteRenderer sp;
Vector3 prevPos;
void Start()
{
sp = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
if (body.velocity.x > 0.1f)
{
flipTrans.localScale = flipTrans.localScale.With(x: 1f);
}
else if (body.velocity.x < -0.1f)
{
flipTrans.localScale = flipTrans.localScale.With(x: -1f);
}
}
}