using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using TMPro; public class TimerSetting : MonoBehaviour { public TextMeshProUGUI timerText; public bool GameAktif = true; public float waktu; float countdown; public GameObject CanvasBerhasil; public GameObject CanvasGagal; void SetTimer() { int menit = Mathf.FloorToInt(waktu / 60); int detik = Mathf.FloorToInt(waktu % 60); timerText.text = menit.ToString("00") + ":" + detik.ToString("00"); } private void TimeOut() { CanvasBerhasil.SetActive(true); } public void RestartGame() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } private void Update() { if (GameAktif) { countdown += Time.deltaTime; if (countdown >= 1) { waktu -= 1; countdown = 0; } } if (GameAktif && waktu <= 0) { Debug.Log("Timeout"); TimeOut(); GameAktif = false; } SetTimer(); } }