using UnityEngine; using UnityEngine.UI; // Nếu dùng UI thường using UnityEngine.SceneManagement; public class FinishGate : MonoBehaviour { [Header("Cài đặt UI")] public GameObject winPanel; // Kéo Panel hoặc Text "You Win" vào đây private void Start() { Time.timeScale = 1; if (winPanel != null) winPanel.SetActive(false); // Ẩn chữ Win lúc đầu game } private void OnTriggerEnter(Collider other) { PlayerInventory player = other.GetComponentInParent(); if (player != null && player.hasTreasure) { WinGame(); } } void WinGame() { if (winPanel != null) winPanel.SetActive(true); // Dừng game Time.timeScale = 0f; // Hiện chuột để bấm nút Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } // --- HÀM CHO CÁC NÚT BẤM --- public void RestartGame() { // Đặt lại thời gian về 1 trước khi load lại nếu không game sẽ bị đứng Time.timeScale = 1f; // Tải lại Scene hiện tại SceneManager.LoadScene("Only AI"); Debug.Log("đang tải lại màn chơi : Only AI"); } public void QuitGame() { Debug.Log("Đang thoát game..."); Application.Quit(); // Thoát file .exe (không có tác dụng trong trình dựng Unity) #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; // Dừng chạy nếu đang ở trong Editor #endif } }