Update ui

This commit is contained in:
manhduyhoang90
2026-06-06 00:25:02 +07:00
parent 7e45faec11
commit a7e07a007f
4 changed files with 539 additions and 86 deletions

View File

@@ -34618,16 +34618,16 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 44324355}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.00003390842}
m_LocalScale: {x: 0.5555556, y: 0.5555556, z: 0.5555556}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 292895766}
m_Father: {fileID: 647991888}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -849, y: 424}
m_AnchoredPosition: {x: -471.6667, y: 235.55554}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &44324357
@@ -41423,7 +41423,7 @@ PrefabInstance:
- target: {fileID: -8789529727683405701, guid: b96d0fcc541b0b947907dd08b9f5beab, type: 3}
propertyPath: notificationText
value:
objectReference: {fileID: 1007024362}
objectReference: {fileID: 1677677840}
- target: {fileID: 600579176653881994, guid: b96d0fcc541b0b947907dd08b9f5beab, type: 3}
propertyPath: m_LocalScale.x
value: 3
@@ -41893,9 +41893,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 62859056}
- {fileID: 44324356}
- {fileID: 1472519200}
- {fileID: 2080548117}
m_Father: {fileID: 963322862}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@@ -91007,7 +91004,7 @@ PrefabInstance:
- target: {fileID: -8789529727683405701, guid: b96d0fcc541b0b947907dd08b9f5beab, type: 3}
propertyPath: notificationText
value:
objectReference: {fileID: 1007024362}
objectReference: {fileID: 1677677840}
- target: {fileID: 600579176653881994, guid: b96d0fcc541b0b947907dd08b9f5beab, type: 3}
propertyPath: m_LocalScale.x
value: 3
@@ -93258,12 +93255,26 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedGameObjects:
- targetCorrespondingSourceObject: {fileID: 556765321, guid: 092f8aa667b2004459042a82a4c9e41d, type: 3}
insertIndex: -1
addedObject: {fileID: 44324356}
- targetCorrespondingSourceObject: {fileID: 556765321, guid: 092f8aa667b2004459042a82a4c9e41d, type: 3}
insertIndex: -1
addedObject: {fileID: 1472519200}
- targetCorrespondingSourceObject: {fileID: 556765321, guid: 092f8aa667b2004459042a82a4c9e41d, type: 3}
insertIndex: -1
addedObject: {fileID: 2080548117}
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 146720, guid: 092f8aa667b2004459042a82a4c9e41d, type: 3}
insertIndex: -1
addedObject: {fileID: 1042553199}
m_SourcePrefab: {fileID: 100100000, guid: 092f8aa667b2004459042a82a4c9e41d, type: 3}
--- !u!224 &647991888 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 556765321, guid: 092f8aa667b2004459042a82a4c9e41d, type: 3}
m_PrefabInstance: {fileID: 647991887}
m_PrefabAsset: {fileID: 0}
--- !u!1 &649955262
GameObject:
m_ObjectHideFlags: 0
@@ -108519,6 +108530,8 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1007024365}
- {fileID: 1677677843}
- {fileID: 2144120087}
- {fileID: 292895766}
m_Father: {fileID: 1625646592}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -108962,7 +108975,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: "\"\u0110\xE3 nh\u1EB7t \u0111\u01B0\u1EE3c r\u01B0\u01A1ng!"
m_text: "B\u1EA1n ch\u01B0a nh\u1EB7t r\u01B0\u01A1ng n\xE0o!"
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -142053,16 +142066,18 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::FinishGate
winPanel: {fileID: 292895765}
welcomeUI: {fileID: 2144120086}
warningUI: {fileID: 1007024362}
hudStar1: {fileID: 0}
hudStar2: {fileID: 0}
hudStar3: {fileID: 0}
winStar1: {fileID: 0}
winStar2: {fileID: 0}
winStar3: {fileID: 0}
hudStar1: {fileID: 44324355}
hudStar2: {fileID: 1472519199}
hudStar3: {fileID: 2080548116}
winStar1: {fileID: 44324355}
winStar2: {fileID: 1472519199}
winStar3: {fileID: 2080548116}
winSound: UI_Win
warningSound: UI_Warning
clickSound: UI_Click
playerTag: Player
--- !u!65 &1398230981
BoxCollider:
m_ObjectHideFlags: 0
@@ -144264,16 +144279,16 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1472519199}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0.00003390842}
m_LocalScale: {x: 0.5555556, y: 0.5555556, z: 0.5555556}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 292895766}
m_Father: {fileID: 647991888}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -701, y: 424}
m_AnchoredPosition: {x: -389.4445, y: 235.55554}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1472519201
@@ -147094,6 +147109,144 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1666249105}
m_CullTransparentMesh: 1
--- !u!1 &1677677840
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1677677843}
- component: {fileID: 1677677842}
- component: {fileID: 1677677841}
m_Layer: 5
m_Name: Text (TMP) (2)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!114 &1677677841
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1677677840}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.TextMeshPro::TMPro.TextMeshProUGUI
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: "\u0110\xE3 nh\u1EB7t \u0111\u01B0\u1EE3c c\u1ED5 v\u1EADt h\xE3y tr\u1ED1n
tho\xE1t ra kh\u1ECFi \u0111\xE2y"
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4278190328
m_fontColor: {r: 0.9716981, g: 0, b: 0, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 36
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 1
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_characterHorizontalScale: 1
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_TextWrappingMode: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 0
m_ActiveFontFeatures: 6e72656b
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_EmojiFallbackSupport: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &1677677842
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1677677840}
m_CullTransparentMesh: 1
--- !u!224 &1677677843
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1677677840}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 963322862}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -50, y: -462}
m_SizeDelta: {x: 422.8404, y: 124.1478}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!43 &1701492490
Mesh:
m_ObjectHideFlags: 0
@@ -147833,7 +147986,7 @@ PrefabInstance:
- target: {fileID: -8789529727683405701, guid: b96d0fcc541b0b947907dd08b9f5beab, type: 3}
propertyPath: notificationText
value:
objectReference: {fileID: 1007024362}
objectReference: {fileID: 1677677840}
- target: {fileID: 600579176653881994, guid: b96d0fcc541b0b947907dd08b9f5beab, type: 3}
propertyPath: m_LocalScale.x
value: 3
@@ -150104,16 +150257,16 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2080548116}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 0.5555556, y: 0.5555556, z: 0.5555556}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 292895766}
m_Father: {fileID: 647991888}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -560, y: 424}
m_AnchoredPosition: {x: -311.11115, y: 235.55554}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2080548118
@@ -151646,6 +151799,143 @@ Transform:
m_Children: []
m_Father: {fileID: 333057066}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2144120086
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2144120087}
- component: {fileID: 2144120089}
- component: {fileID: 2144120088}
m_Layer: 5
m_Name: Text (TMP) (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &2144120087
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2144120086}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 963322862}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -50, y: -462}
m_SizeDelta: {x: 422.8404, y: 124.1478}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2144120088
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2144120086}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.TextMeshPro::TMPro.TextMeshProUGUI
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: "Ch\xE0o m\u1EEBng!"
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4278190328
m_fontColor: {r: 0.9716981, g: 0, b: 0, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 36
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 1
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_characterHorizontalScale: 1
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_TextWrappingMode: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 0
m_ActiveFontFeatures: 6e72656b
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_EmojiFallbackSupport: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &2144120089
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2144120086}
m_CullTransparentMesh: 1
--- !u!1001 &2145701567
PrefabInstance:
m_ObjectHideFlags: 0

View File

@@ -1,20 +1,21 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using Hallucinate.Audio; // Import namespace hệ thống âm thanh của bạn
using Hallucinate.Audio;
public class FinishGate : MonoBehaviour
{
[Header("Cài đặt UI Chính")]
public GameObject winPanel;
public GameObject warningUI; // THÔNG BÁO: "Bạn chưa nhặt rương nào!"
public GameObject welcomeUI; // THÔNG BÁO 1: "Chào mừng!"
public GameObject warningUI; // THÔNG BÁO 2: "Bạn chưa nhặt rương nào!"
[Header("Cài đặt Sao trên HUD (Giao diện chính lúc đang chạy)")]
[Header("Cài đặt Sao trên HUD")]
public GameObject hudStar1;
public GameObject hudStar2;
public GameObject hudStar3;
[Header("Cài đặt Sao trên Bảng Win (Kết thúc game)")]
[Header("Cài đặt Sao trên Bảng Win")]
public GameObject winStar1;
public GameObject winStar2;
public GameObject winStar3;
@@ -24,53 +25,54 @@ public class FinishGate : MonoBehaviour
public string warningSound = "UI_Warning";
public string clickSound = "UI_Click";
[Header("Cấu hình Tag Hệ thống")]
[Tooltip("Tag của Người chơi/NPC dùng để kích hoạt Gate")]
[Header("Cấu hình Tag")]
public string playerTag = "Player";
private bool hasEnteredOnce = false; // Theo dõi lần chạm cổng đầu tiên
private void Start()
{
// Đảm bảo thời gian chạy bình thường khi load màn
Time.timeScale = 1f;
// Ẩn các bảng UI khi vừa vào game
if (winPanel != null) winPanel.SetActive(false);
if (welcomeUI != null) welcomeUI.SetActive(false);
if (warningUI != null) warningUI.SetActive(false);
// Reset trạng thái sao về 0 lúc bắt đầu
UpdateStarsUI(0);
UpdateWinStarsUI(0);
}
private void OnTriggerEnter(Collider other)
{
// KIỂM TRA 1: Phải đúng Tag quy định (Nên để là "Player")
if (other.CompareTag(playerTag))
{
// KIỂM TRA 2: Tìm linh hoạt component PlayerInventory ở cả con và cha
PlayerInventory player = other.GetComponentInChildren<PlayerInventory>();
if (player == null) player = other.GetComponentInParent<PlayerInventory>();
if (player != null)
{
// TRƯỜNG HỢP 1: Đã đi đến cuối bản đồ nhặt được ít nhất 1 cổ vật -> CHIẾN THẮNG
if (player.treasuresCollected > 0)
{
Debug.Log($"<color=green>[Gate]</color> VỀ ĐÍCH HỢP LỆ! Hoàn thành với {player.treasuresCollected} cổ vật.");
WinGame(player.treasuresCollected);
}
// TRƯỜNG HỢP 2: Đi qua cổng lúc bắt đầu game (chưa nhặt được gì) -> HIỆN CẢNH BÁO
else
{
Debug.Log("<color=yellow>[Gate]</color> NPC/Player chưa nhặt cổ vật! Hãy chạy đến cuối map.");
StopAllCoroutines();
StartCoroutine(ShowTempUI(warningUI));
// Nếu là lần đầu tiên -> Hiện Welcome. Nếu là lần sau -> Hiện Warning.
if (!hasEnteredOnce)
{
hasEnteredOnce = true;
StartCoroutine(ShowTempUI(welcomeUI));
}
else
{
StartCoroutine(ShowTempUI(warningUI));
}
}
}
}
}
// Hàm public được gọi từ TreasureItem để cập nhật HUD ngay lập tức khi vừa nhặt đồ
public void UpdateStarsUI(int count)
{
if (hudStar1 != null) hudStar1.SetActive(count >= 1);
@@ -78,7 +80,6 @@ public class FinishGate : MonoBehaviour
if (hudStar3 != null) hudStar3.SetActive(count >= 3);
}
// Hàm nội bộ cập nhật số sao trên bảng kết quả tổng kết
private void UpdateWinStarsUI(int count)
{
if (winStar1 != null) winStar1.SetActive(count >= 1);
@@ -94,10 +95,7 @@ public class FinishGate : MonoBehaviour
UpdateWinStarsUI(count);
}
// Phát âm thanh thắng cuộc toàn cục
AudioManager.PlayGlobal(winSound);
// Dừng thời gian game và mở khóa chuột
Time.timeScale = 0f;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
@@ -107,9 +105,12 @@ public class FinishGate : MonoBehaviour
{
if (ui == null) yield break;
// Tắt tất cả UI tạm thời khác trước khi bật cái mới để tránh đè chữ
if (welcomeUI != null) welcomeUI.SetActive(false);
if (warningUI != null) warningUI.SetActive(false);
ui.SetActive(true);
// Chỉ phát âm thanh cảnh báo nếu đây là UI cảnh báo thiếu đồ
if (ui == warningUI)
{
AudioManager.PlayGlobal(warningSound);
@@ -119,7 +120,6 @@ public class FinishGate : MonoBehaviour
ui.SetActive(false);
}
// --- CÁC HÀM ĐIỀU HƯỚNG UI BUTTONS ---
public void RestartGame()
{
AudioManager.PlayGlobal(clickSound);
@@ -131,7 +131,6 @@ public class FinishGate : MonoBehaviour
{
AudioManager.PlayGlobal(clickSound);
Application.Quit();
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif

View File

@@ -5,7 +5,8 @@ using Hallucinate.Audio;
public class TreasureItem : MonoBehaviour
{
[Header("Cài đặt UI thông báo")]
public GameObject notificationText; // Kéo Text "Đã nhặt Cổ vật" vào đây
[Tooltip("Kéo Text 'Đã nhặt được cổ vật hãy trốn thoát ra khỏi đây' vào đây")]
public GameObject notificationText;
[Header("Cài đặt Âm thanh")]
public string pickupSound = "Item_Pickup";
@@ -13,12 +14,10 @@ public class TreasureItem : MonoBehaviour
[Header("Cấu hình Tag")]
public string playerTag = "Player";
// Biến cờ để tránh việc va chạm 2 lần trong cùng 1 frame
private bool isCollected = false;
private void Start()
{
// Đảm bảo UI thông báo luôn tắt khi bắt đầu game
if (notificationText != null)
{
notificationText.SetActive(false);
@@ -27,7 +26,6 @@ public class TreasureItem : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
// 1. Chỉ xử lý khi chạm đúng Player và rương chưa bị nhặt
if (!isCollected && other.CompareTag(playerTag))
{
PlayerInventory player = other.GetComponentInChildren<PlayerInventory>();
@@ -35,30 +33,22 @@ public class TreasureItem : MonoBehaviour
if (player != null)
{
// Khóa lại để không bị kích hoạt nhiều lần
isCollected = true;
// 2. 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}");
// 3. Cập nhật sao trên HUD (Sử dụng hàm Unity 6: FindAnyObjectByType)
FinishGate gate = Object.FindAnyObjectByType<FinishGate>();
if (gate != null)
{
gate.UpdateStarsUI(player.treasuresCollected);
}
// 4. Kích hoạt trạng thái truy đuổi cho toàn bộ Enemy AI
SetEnemiesAlertState(true);
// 5. Chạy âm thanh nhặt đồ
if (AudioManager.Instance != null)
{
AudioManager.Instance.Play(pickupSound, position: transform.position);
}
// 6. Xử lý hiện UI và làm biến mất rương an toàn
StartCoroutine(HandlePickupRoutine());
}
}
@@ -66,48 +56,37 @@ public class TreasureItem : MonoBehaviour
private void SetEnemiesAlertState(bool state)
{
// Sử dụng hàm chuẩn Unity 6+
EnemyAI[] allEnemies = Object.FindObjectsByType<EnemyAI>(FindObjectsSortMode.None);
foreach (EnemyAI enemy in allEnemies)
{
if (enemy != null)
{
enemy.playerHasArtifact = state;
}
if (enemy != null) enemy.playerHasArtifact = state;
}
}
private IEnumerator HandlePickupRoutine()
{
// Ẩn rương đi trước (tắt hiển thị và va chạm)
HideTreasureModel();
// Bật UI thông báo "Đã nhặt Cổ vật"
if (notificationText != null)
{
notificationText.SetActive(true);
}
// Chờ 2 giây
yield return new WaitForSeconds(2f);
yield return new WaitForSeconds(3f); // Tăng lên 3s để người chơi kịp đọc dòng chữ dài
// Tắt UI thông báo
if (notificationText != null)
{
notificationText.SetActive(false);
}
// Khi UI đã xử lý xong, mới chính thức tắt hoàn toàn GameObject rương
gameObject.SetActive(false);
}
private void HideTreasureModel()
{
// Tắt va chạm chính của rương
Collider col = GetComponent<Collider>();
if (col != null) col.enabled = false;
// Tắt model hiển thị 3D của rương (bao gồm cả object cha và con)
MeshRenderer[] renderers = GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer r in renderers)
{