// Update is called once per frame void Update() { switch (state) { case MatchManager.AIState.WaitingToServe: Stop(); if (waitTime < waitingToServeTime) { waitTime += Time.deltaTime; } else { state = MatchManager.AIState.WaitAnimation; from = MatchManager.AIState.Serve; waitTime = 0; Animator.SetTrigger("Serve"); } break; case MatchManager.AIState.Serve: Serve(); state = MatchManager.AIState.MoveToCenter; break; case MatchManager.AIState.HitBall: HitBall(); state = MatchManager.AIState.MoveToCenter; break; case MatchManager.AIState.WaitAnimation: if (from == MatchManager.AIState.Serve) { if (waitTime < waitAnimationTime) { waitTime++; } else { state = MatchManager.AIState.Serve; waitTime += Time.deltaTime; Stop(); } } else { state = MatchManager.AIState.HitBall; Stop(); } break; case MatchManager.AIState.MoveToCenter: MoveToCenter(); break; case MatchManager.AIState.MovingToBall: MoveToBall(); float dist = Vector3.Distance(ball.transform.position, transform.position); if (dist <= hitThreshold) { state = MatchManager.AIState.WaitAnimation; from = MatchManager.AIState.HitBall; } break; case MatchManager.AIState.Stop: Stop(); break; } }
public void SetState(MatchManager.AIState newState) { state = newState; }