update
This commit is contained in:
59
Assets/Scripts/FinishGate.cs
Normal file
59
Assets/Scripts/FinishGate.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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<PlayerInventory>();
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/FinishGate.cs.meta
Normal file
2
Assets/Scripts/FinishGate.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b97ebb3ed2a03534cbba257defc374a6
|
||||
7
Assets/Scripts/PlayerInventory.cs
Normal file
7
Assets/Scripts/PlayerInventory.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
public class PlayerInventory : MonoBehaviour
|
||||
{
|
||||
// Biến kiểm tra xem người chơi đã nhặt kho báu chưa
|
||||
public bool hasTreasure = false;
|
||||
public int score = 0; // Điểm số nếu bạn muốn cộng thêm
|
||||
}
|
||||
2
Assets/Scripts/PlayerInventory.cs.meta
Normal file
2
Assets/Scripts/PlayerInventory.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16509f68a17b8004096bcf4acce328d6
|
||||
18
Assets/Scripts/TreasureItem.cs
Normal file
18
Assets/Scripts/TreasureItem.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TreasureItem : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
// Kiểm tra xem thứ chạm vào có script PlayerInventory không
|
||||
PlayerInventory player = other.GetComponentInParent<PlayerInventory>();
|
||||
if (player != null && !player.hasTreasure)
|
||||
{
|
||||
player.hasTreasure = true;
|
||||
Debug.Log("Đã nhặt kho báu!");
|
||||
|
||||
// Làm vật phẩm biến mất
|
||||
gameObject.SetActive(false); // Hoặc Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/TreasureItem.cs.meta
Normal file
2
Assets/Scripts/TreasureItem.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bb610721d69d41438dc6d3a2b000705
|
||||
Reference in New Issue
Block a user