Поворот спрайта Unity 2D
Вот написал скрипт для патрулирования уровня. Данный персонаж двигается только по двум точкам. Не могу разобраться как сделать поворот спрайта на 180 градусов при достижении точки.
public class WalkingMonster : Entity
{
[SerializeField] private Transform _path;
[SerializeField] private float _speed;
//private Vector3 dir;
//private SpriteRenderer sprite;
private Transform[] _points;
private int _currentPoint;
private void Start()
{
//dir = transform.right;
_points = new Transform[_path.childCount];
for (int i = 0; i < _path.childCount; i++)
{
_points[i] = _path.GetChild(i);
}
}
private void Update()
{
Transform target = _points[_currentPoint];
transform.position = Vector3.MoveTowards(transform.position, target.position, _speed * Time.deltaTime);
if (transform.position == target.position)
{
_currentPoint++;
if (_currentPoint >= _points.Length)
{
// sprite.flipX = dir.x > 0.0f;
_currentPoint = 0;
}
}
}
}
В path я закидываю пустой Gameobject, у которого 2 дочерних элемента (2 точки)
Источник: Stack Overflow на русском