Why the ping pong is not working on the waypoints?
Your editor freezes because in the case that pingPongEnabled
is set to true
you do
if (pingPongEnabled)
{
transform.position = Vector3.MoveTowards(pingPongStart, WayPoints[CurrentWayPoint].transform.position, Mathf.PingPong(Time.time * 1, 1) * Time.deltaTime);
continue;
}
without yield
ing within the loop -> due to continue
it immediately goes to the next iteration without the exit condition ever fulfilled.
You want to make sure to always do
if (pingPongEnabled)
{
transform.position = Vector3.MoveTowards(pingPongStart, WayPoints[CurrentWayPoint].transform.position, Mathf.PingPong(Time.time * 1, 1) * Time.deltaTime);
yield return null;
continue;
}
in order to at least wait until the next frame with the next iteration
Anyway, this
transform.position = Vector3.MoveTowards(pingPongStart, WayPoints[CurrentWayPoint].transform.position, Mathf.PingPong(Time.time * 1, 1) * Time.deltaTime);
doesn't really "ping-pong" like you would probably expect. It always starts back at pingPongStart
and moves a single step towards the waypoint and only goes a bit further or less.
You probably rather ment
transform.position = Vector3.Lerp(pingPongStart, WayPoints[CurrentWayPoint].transform.position, Mathf.PingPong(Time.time, 1));