void Awake() { state = POINTMOVESTATE.MOVE; max = checkPoints.Length; time = Time.fixedTime; prePos = (Vector2)transform.position; }
void MoveStraight() { switch (state) { case POINTMOVESTATE.MOVE: Vector2 goal = (Vector2)(checkPoints [count + 1].transform.position - transform.position); vel = goal.normalized * speed / 100; transform.Translate(vel); if (Mathf.Abs(checkPoints[count + 1].transform.position.x - transform.position.x) <= 0.1 && Mathf.Abs(checkPoints[count + 1].transform.position.y - transform.position.y) <= 0.1 ) { arrivedAtGoal = true; if (count + 2 == max) { count = -1; } else { count++; } state = POINTMOVESTATE.WAIT; time = Time.fixedTime; } break; case POINTMOVESTATE.WAIT: vel = Vector2.zero; if (Time.fixedTime - time >= wait) { state = POINTMOVESTATE.MOVE; } break; } }