2024-02-03 21:44:51 +01:00
|
|
|
|
using UnityEngine;
|
2024-02-04 05:40:23 +01:00
|
|
|
|
using UnityUtils;
|
2024-02-03 21:44:51 +01:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-02-03 21:44:51 +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-03 21:44:51 +01:00
|
|
|
|
{
|
2024-02-04 05:40:23 +01:00
|
|
|
|
flipTrans.localScale = flipTrans.localScale.With(x: 1f);
|
2024-02-03 21:44:51 +01:00
|
|
|
|
}
|
2024-02-04 05:40:23 +01:00
|
|
|
|
else if (body.velocity.x < -0.1f)
|
2024-02-03 21:44:51 +01:00
|
|
|
|
{
|
2024-02-04 05:40:23 +01:00
|
|
|
|
flipTrans.localScale = flipTrans.localScale.With(x: -1f);
|
2024-02-03 21:44:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|