Код: Выделить всё
public class Enemy : MonoBehaviour
{
public float movementSpeed = 5.0f;
Vector2 pointA;
Vector2 pointB;
Rigidbody2D rb;
void Start()
{
rb=GetComponent();
pointA = new Vector2(9, 0);
pointB = new Vector2(2, 0);
}
void Update()
{
float move = Mathf.PingPong(Time.time * movementSpeed, 1);
transform.position = Vector2.Lerp(pointA, pointB, move);
}
}
Для перемещения объекта вперед и назад
Подробнее здесь: https://stackoverflow.com/questions/791 ... -and-forth