protected IEnumerator StartTimer(IGameWindow gameWindow, Action OnComplete = null) { _audioService.StartGameMusic(); float seconds = 4; previousSecondCounter = seconds; Rigidbody _prb = null; if (_playerCar != null) { _prb = _playerCar.GetComponent <Rigidbody>(); } Rigidbody _erb = null; if (_ghostCar != null) { _erb = _ghostCar.GetComponent <Rigidbody>(); } gameWindow.Get_TimerText().GetComponent <CanvasGroup>().alpha = 1; while (seconds > 1) { gameWindow.Get_TimerText().text = (seconds - (seconds % 1)).ToString(); if (previousSecondCounter != (seconds - (seconds % 1)) && seconds != 4) { previousSecondCounter = (seconds - (seconds % 1)); _audioService.RM_PlayOneShot(audioCounterPath); } yield return(new WaitForEndOfFrame()); seconds -= Time.deltaTime; if (_prb != null) { _prb.velocity = new Vector3(0, _prb.velocity.y, _prb.velocity.z); } if (_erb != null) { _erb.velocity = new Vector3(0, _erb.velocity.y, _erb.velocity.z); } _playerCar.transform.position = new Vector3(_playerCar.transform.position.x, _playerCar.transform.position.y, 2); } gameWindow.Get_TimerText().GetComponent <CanvasGroup>().alpha = 0; _playerCar.EnablePlayerControll(true); if (_gameData.ghostData.Count > 0) { _ghostCar.EnableEnemyControll(true); } gameWindow.Get_PauseButton().interactable = true; // invoke callback if (OnComplete != null) { OnComplete(); } }