update babe

This commit is contained in:
2026-06-04 17:49:04 +07:00
parent c545401b7a
commit b61b79c82e
60 changed files with 5164 additions and 82 deletions

View File

@@ -121,7 +121,7 @@ public class EnemyAI : MonoBehaviour
private NodeState ActionPatrol()
{
Debug.Log("Patrolling...");
// Debug.Log("Patrolling...");
agent.isStopped = false; // Đảm bảo NPC được phép di chuyển
agent.speed = moveSpeed * 0.5f; // Đi dạo nên đi chậm lại một chút
@@ -154,7 +154,7 @@ public class EnemyAI : MonoBehaviour
{
if (player == null) return NodeState.Failure;
Debug.Log("Chasing Player");
// Debug.Log("Chasing Player");
agent.isStopped = false;
agent.speed = moveSpeed; // Phục hồi tốc độ rượt đuổi
@@ -167,7 +167,7 @@ public class EnemyAI : MonoBehaviour
{
if (player == null) return NodeState.Failure;
Debug.Log("Focus and Shoot!");
// Debug.Log("Focus and Shoot!");
// Dừng NavMeshAgent lại để đứng bắn, tránh bị trượt
agent.isStopped = true;
@@ -196,7 +196,7 @@ public class EnemyAI : MonoBehaviour
{
if (laserPrefab == null || firePoint == null) return;
Instantiate(laserPrefab, firePoint.position, firePoint.rotation);
Debug.Log("Laser Shot!");
// Debug.Log("Laser Shot!");
}
#endregion

View File

@@ -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
}
}
}

View File

@@ -3,6 +3,6 @@ using UnityEngine;
public class PlayerInventory : MonoBehaviour
{
[Header("Cấu hình túi đồ")]
public int treasuresCollected = 0; // Đếm số lượng rương đã nhặt
public int totalTreasuresNeeded = 3; // Số lượng cần để thắng
}
public int treasuresCollected = 0; // Số lượng rương đang cầm trên người trong lần chạy này
public int totalTreasuresNeeded = 3; // Mục tiêu tối đa (3 rương = 3 sao)
}

View File

@@ -4,31 +4,49 @@ using System.Collections;
public class TreasureItem : MonoBehaviour
{
[Header("Cài đặt UI thông báo")]
public GameObject notificationText;
private void Start()
{
if (notificationText != null) notificationText.SetActive(false);
}
public GameObject notificationText; // Text "Đã nhặt Cổ vật"
private void OnTriggerEnter(Collider other)
{
// Tìm PlayerInventory ở đối tượng hoặc cha của nó
PlayerInventory player = other.GetComponentInParent<PlayerInventory>();
if (player != null)
if (other.CompareTag("Player"))
{
player.treasuresCollected += 1;
Debug.Log("Đã nhặt rương! Tổng cộng: " + player.treasuresCollected);
if (notificationText != null)
{
StopAllCoroutines();
StartCoroutine(ShowNotification());
}
PlayerInventory player = other.GetComponentInChildren<PlayerInventory>();
if (player == null) player = other.GetComponentInParent<PlayerInventory>();
// Biến mất rương
gameObject.SetActive(false);
if (player != null)
{
// 1. Tăng số lượng rương đang giữ
player.treasuresCollected++;
Debug.Log($"<color=cyan>[Chest]</color> NHẶT THÀNH CÔNG! Số rương hiện tại: {player.treasuresCollected}");
// 2. Cập nhật sao trên HUD ngay lập tức (Tìm FinishGate để mượn hàm update)
FinishGate gate = Object.FindAnyObjectByType<FinishGate>();
if (gate != null)
{
gate.UpdateStarsUI(player.treasuresCollected);
}
// 3. Kích hoạt trạng thái truy đuổi cho toàn bộ Enemy AI
SetEnemiesAlertState(true);
if (notificationText != null)
{
StopAllCoroutines();
StartCoroutine(ShowNotification());
}
// Biến mất rương
gameObject.SetActive(false);
}
}
}
private void SetEnemiesAlertState(bool state)
{
EnemyAI[] allEnemies = Object.FindObjectsByType<EnemyAI>(FindObjectsSortMode.None);
foreach (EnemyAI enemy in allEnemies)
{
enemy.playerHasArtifact = state;
}
}
@@ -38,4 +56,4 @@ public class TreasureItem : MonoBehaviour
yield return new WaitForSeconds(2f);
notificationText.SetActive(false);
}
}
}