IEnumerator HandleTimer() { currentSecondsLeft = turnSeconds; while (currentSecondsLeft > 0) { currentSecondsLeft -= Time.deltaTime; if (p1Tank.isAcceptingInput) { p1Tank.timeRemaining -= Time.deltaTime; } else { p2Tank.timeRemaining -= Time.deltaTime; } timer.UpdateText(p1Tank.timeRemaining, p2Tank.timeRemaining, currentSecondsLeft); string tankDescription; if (p1Tank.isAcceptingInput) { tankDescription = "Red Tank: "; } else { tankDescription = "Blue Tank: "; } print(tankDescription + currentSecondsLeft + " / " + turnSeconds); yield return(null); } SwapTurn(); }
private void Update() { if (EnemiesAlive > 0) { return; } if (countdown <= 0f) { StartCoroutine(SpawnWave()); countdown = timeBetweenWaves; return; } countdown -= Time.deltaTime; countdown = Mathf.Clamp(countdown, 0, Mathf.Infinity); TimerUI.UpdateText(string.Format("{0:00.00}", countdown)); }
IEnumerator Turn() { CameraManager.instance.PanTo(currentPlayer.transform.position); // 5 second to press any button TurnWaitingCanvas.enabled = true; float waitTime = 5f; float startWait = Time.time; while (Time.time < startWait + waitTime && !Input.anyKeyDown) { turnWaitingText.text = "Press any button to continue... " + (5 - (Time.time - startWait)).ToString("f0"); yield return(null); } TurnWaitingCanvas.enabled = false; // SHOW TERMINAL terminalCanvas.enabled = true; currentPlayer.isAwaitingInput = true; // start turn timer float turn = turnTimer; while (turn >= 0 && !currentPlayer.hasSubmitted) { currentPlayer.timeRemaining -= Time.deltaTime; turn -= Time.deltaTime; // update timers text timers.UpdateText(tank1.timeRemaining, tank2.timeRemaining, turn); yield return(null); } terminalCanvas.enabled = false; while (GuidedRocket.isActive) { yield return(null); } SwapTurn(); }