void Update() { bool JustStarted = false; if (StateLeftTime > 0) { StateLeftTime -= Time.deltaTime; } else { CurrentState = NextState; StateLeftTime = GetState().StateTime; NextState = GetState().NextState; JustStarted = true; } switch (GetState().State) { case (TrackState.Arriving): if (JustStarted) { Audio.Play(); } RigidBody.MovePosition(Vector3.Lerp(LoadingLocation, WaitingLocation, Mathf.InverseLerp(0, GetState().StateTime, StateLeftTime))); break; case (TrackState.Opening): if (JustStarted) { Door.UnLock(); InvisibleWall.enabled = false; } break; case (TrackState.Closing): if (JustStarted) { Door.TryLock(); if (CurrentState == 3) { Audio.clip = CloseSound; Audio.Play(); } ProgressBar.Hide(); } if (Door.CheckLock()) { StateLeftTime = 0; Door.Freeze(); } break; case (TrackState.Leaving): if (JustStarted) { Audio.clip = LeavingSound; Audio.Play(); ProgressBar.Hide(); if (Door.CheckLock()) { Door.Freeze(); CollectedBoxes.AddRange(BoxProcessor.CollectBoxes()); } else { Door.Break(); //Audio.clip = DoorBrokenSound; //Audio.Play(); } InvisibleWall.enabled = true; } RigidBody.MovePosition(Vector3.Lerp(WaitingLocation, LoadingLocation, Mathf.InverseLerp(0, GetState().StateTime, StateLeftTime))); break; case (TrackState.GiveReward): if (JustStarted) { CollectedBoxes.AddRange(BoxProcessor.CollectBoxes()); AllowedProcessReward = true; } break; case (TrackState.Wait): if (JustStarted) { ProgressBar.Show(); } ProgressBar.RefreshValue(Mathf.InverseLerp(0, GetState().StateTime, StateLeftTime)); break; } TickReward(); }