void OnStateUpdate() { switch (m_CurrentState) { case CurrentState.Spawn: if (m_CurrentWaitPoint == 0) { m_NavMeshAgent.SetDestination(m_EntryPoint.m_WaitingPoint.transform.position); if (m_NavMeshAgent.remainingDistance < 0.2f) { SwitchState(CurrentState.Idle); } } else { SwitchState(CurrentState.InQueue); } break; case CurrentState.InQueue: if (m_EntryPoint.m_MustReload) { SwitchState(CurrentState.MovingInQueue); } break; case CurrentState.MovingInQueue: if (m_EntryPoint.m_MustReload) { SwitchState(CurrentState.MovingInQueue); } break; case CurrentState.Idle: m_Timer += Time.deltaTime; if (m_Timer >= m_IdleTimer) { if (Random.Range(0f, 1f) > m_ChairObject) { SwitchState(CurrentState.MovingTowardChair); } else { SwitchState(CurrentState.MovingTowardObject); } } break; case CurrentState.MovingTowardChair: if (Vector3.Distance(transform.position, m_NavMeshAgent.destination) < 0.6f) { SwitchState(CurrentState.Sitting); } break; case CurrentState.MovingTowardObject: if (Vector3.Distance(transform.position, m_NavMeshAgent.destination) < 1.0f) { m_Animator.CrossFade("Boy_TableFlip", 0.0f); transform.rotation = Quaternion.LookRotation((m_Throwable.transform.position - transform.position)); m_Timer += Time.deltaTime; if (m_Timer >= 0.4f) { SwitchState(CurrentState.ThrowSomething); } } break; case CurrentState.ThrowSomething: m_Timer += Time.deltaTime; if (m_Timer > 2.0f) { SwitchState(CurrentState.MovingTowardChair); } break; case CurrentState.Sitting: m_Timer += Time.deltaTime; vfx_Poulet.Play(true); RaycastHit plateHit; Ray forwardRay = new Ray(transform.position + Vector3.up * 0.3f, transform.forward); if (Physics.Raycast(forwardRay, out plateHit, m_PlateRayDistance, m_RaycastLayer, QueryTriggerInteraction.Collide)) { Plate m_Plate = plateHit.collider.GetComponentInParent <Plate>(); if (m_Plate != null) { if (m_Plate.plateState == Plate.PlateState.Full) { SwitchState(CurrentState.Eating); } else if (m_Plate.plateState == Plate.PlateState.Garbage) { SwitchState(CurrentState.Spitting); } if (m_Timer >= m_IdleTimer) { vfx_Angry.Play(true); SwitchState(CurrentState.Berserker); } } } else { if (m_Timer >= m_IdleTimer) { vfx_Angry.Play(true); SwitchState(CurrentState.Berserker); } } break; case CurrentState.Eating: m_Timer += Time.deltaTime; RaycastHit plateHit2; Ray forwardRay2 = new Ray(transform.position + Vector3.up * 0.3f, transform.forward); if (Physics.Raycast(forwardRay2, out plateHit2, m_PlateRayDistance, m_RaycastLayer, QueryTriggerInteraction.Collide)) { m_Plate = plateHit2.collider.GetComponentInParent <Plate>(); if (m_Plate == null) { vfx_Angry.Play(true); SwitchState(CurrentState.Berserker); } else { if (m_Timer > 4.0f) { if (m_HaveEat) { if (Random.Range(0f, 1f) > (1 - m_SpitAfterFirstEat)) { vfx_Happy.Play(true); SwitchState(CurrentState.SittingIdle); } else { SwitchState(CurrentState.Spitting); } } else { if (Random.Range(0f, 1f) > (1 - m_SpitAfterFirstEat)) { vfx_Happy.Play(true); SwitchState(CurrentState.SittingIdle); } else { SwitchState(CurrentState.Spitting); } } m_Plate.Consume(); } } } break; case CurrentState.SittingIdle: m_Timer += Time.deltaTime; if (m_Timer >= m_IdleTimer) { SwitchState(CurrentState.MovingTowardExit); } break; case CurrentState.Spitting: m_Timer += Time.deltaTime; if (m_Timer > 2.0f) { Instantiate(vfx_Spit, transform.position, Quaternion.identity); SwitchState(CurrentState.MovingTowardExit); } break; case CurrentState.MovingTowardExit: if (Vector3.Distance(transform.position, m_NavMeshAgent.destination) < 0.3f) { SwitchState(CurrentState.Disapear); } break; case CurrentState.Disapear: break; case CurrentState.PickUp: break; case CurrentState.Release: m_NavMeshAgent.enabled = true; RaycastHit releaseHit; Ray downRay = new Ray(transform.position, Vector3.down); if (Physics.Raycast(downRay, out releaseHit, 100.0f, m_RaycastLayer, QueryTriggerInteraction.Collide)) { m_Chair = releaseHit.collider.GetComponentInParent <Chair>(); if (m_Chair != null) { SwitchState(CurrentState.Sitting); } } else { if (m_HaveEat) { SwitchState(CurrentState.MovingTowardExit); } else { if (Random.Range(0f, 1f) > m_FlipAfterDrop) { SwitchState(CurrentState.MovingTowardChair); } else { SwitchState(CurrentState.MovingTowardObject); } } } break; case CurrentState.Berserker: if (Random.Range(0f, 1f) > (1 - m_BerserkerFlip)) { SwitchState(CurrentState.MovingTowardObject); } else { SwitchState(CurrentState.MovingTowardExit); } break; } }