update babe
This commit is contained in:
@@ -5,86 +5,102 @@ using System.Collections;
|
||||
public class FinishGate : MonoBehaviour
|
||||
{
|
||||
[Header("Cài đặt UI Chính")]
|
||||
public GameObject winPanel; // Bảng You Win
|
||||
public GameObject warningUI; // Chữ "Chưa đủ rương"
|
||||
public GameObject winPanel;
|
||||
public GameObject warningUI; // Thông báo "Bạn chưa nhặt rương nào!"
|
||||
|
||||
[Header("Cài đặt Sao (Stars)")]
|
||||
public GameObject star1;
|
||||
public GameObject star2;
|
||||
public GameObject star3;
|
||||
[Header("Cài đặt Sao trên HUD (Giao diện chính)")]
|
||||
public GameObject hudStar1;
|
||||
public GameObject hudStar2;
|
||||
public GameObject hudStar3;
|
||||
|
||||
[Header("Cài đặt Sao trên Bảng Win (Kết thúc)")]
|
||||
public GameObject winStar1;
|
||||
public GameObject winStar2;
|
||||
public GameObject winStar3;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Reset thời gian và ẩn UI lúc bắt đầu
|
||||
Time.timeScale = 1f;
|
||||
|
||||
if (winPanel != null) winPanel.SetActive(false);
|
||||
if (warningUI != null) warningUI.SetActive(false);
|
||||
|
||||
if (star1) star1.SetActive(false);
|
||||
if (star2) star2.SetActive(false);
|
||||
if (star3) star3.SetActive(false);
|
||||
// Ẩn tất cả sao lúc bắt đầu
|
||||
UpdateStarsUI(0);
|
||||
UpdateWinStarsUI(0);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
PlayerInventory player = other.GetComponentInParent<PlayerInventory>();
|
||||
|
||||
if (player != null)
|
||||
if (other.CompareTag("Check"))
|
||||
{
|
||||
if (player.treasuresCollected >= player.totalTreasuresNeeded)
|
||||
PlayerInventory player = other.GetComponentInChildren<PlayerInventory>();
|
||||
if (player == null) player = other.GetComponentInParent<PlayerInventory>();
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
WinGame(player.treasuresCollected);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Chưa đủ rương! Bạn cần " + player.totalTreasuresNeeded);
|
||||
if (warningUI != null) StartCoroutine(ShowWarning());
|
||||
if (player.treasuresCollected > 0)
|
||||
{
|
||||
Debug.Log($"<color=green>[Gate]</color> VỀ ĐÍCH! Kết thúc màn chơi với {player.treasuresCollected} sao.");
|
||||
WinGame(player.treasuresCollected);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("<color=yellow>[Gate]</color> Bạn chưa nhặt rương nào, hãy đi tìm rương trước khi về.");
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(ShowTempUI(warningUI));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ShowWarning()
|
||||
// Hàm public để TreasureItem có thể gọi cập nhật HUD ngay khi nhặt
|
||||
public void UpdateStarsUI(int count)
|
||||
{
|
||||
warningUI.SetActive(true);
|
||||
yield return new WaitForSeconds(2f);
|
||||
warningUI.SetActive(false);
|
||||
if (hudStar1) hudStar1.SetActive(count >= 1);
|
||||
if (hudStar2) hudStar2.SetActive(count >= 2);
|
||||
if (hudStar3) hudStar3.SetActive(count >= 3);
|
||||
}
|
||||
|
||||
void UpdateWinStarsUI(int count)
|
||||
{
|
||||
if (winStar1) winStar1.SetActive(count >= 1);
|
||||
if (winStar2) winStar2.SetActive(count >= 2);
|
||||
if (winStar3) winStar3.SetActive(count >= 3);
|
||||
}
|
||||
|
||||
void WinGame(int count)
|
||||
{
|
||||
if (winPanel != null) winPanel.SetActive(true);
|
||||
|
||||
// Hiện sao dựa trên số lượng nhặt được
|
||||
if (count >= 1 && star1) star1.SetActive(true);
|
||||
if (count >= 2 && star2) star2.SetActive(true);
|
||||
if (count >= 3 && star3) star3.SetActive(true);
|
||||
if (winPanel != null)
|
||||
{
|
||||
winPanel.SetActive(true);
|
||||
UpdateWinStarsUI(count); // Hiện số sao tương ứng trên bảng kết thúc
|
||||
}
|
||||
|
||||
// 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 ---
|
||||
IEnumerator ShowTempUI(GameObject ui)
|
||||
{
|
||||
if (ui == null) yield break;
|
||||
ui.SetActive(true);
|
||||
yield return new WaitForSeconds(3f);
|
||||
ui.SetActive(false);
|
||||
}
|
||||
|
||||
public void RestartGame()
|
||||
{
|
||||
Debug.Log("Đang tải lại màn chơi...");
|
||||
Time.timeScale = 1f;
|
||||
|
||||
// Sử dụng buildIndex để tránh lỗi tên scene
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||||
}
|
||||
|
||||
public void QuitGame()
|
||||
{
|
||||
Debug.Log("Đang thoát game...");
|
||||
Application.Quit();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user