From d9741b0290a51acd512af3734ac912df9c4d12fc Mon Sep 17 00:00:00 2001 From: rezazfn Date: Tue, 4 Feb 2025 12:03:44 +0800 Subject: [PATCH] game: misc (bedroom task isnt fully working yet) --- .../3.0.3/Scenes/Game.unity | 17 ++++++++++ Game/Assets/Scripts/BedroomTask.cs | 34 +++++++++++++++---- Game/Assets/Scripts/Trash.cs | 8 ++--- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Scenes/Game.unity b/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Scenes/Game.unity index 57873e1..1c97ad8 100644 --- a/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Scenes/Game.unity +++ b/Game/Assets/Samples/XR Interaction Toolkit/3.0.3/Scenes/Game.unity @@ -315240,6 +315240,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 2057524443} + - component: {fileID: 2057524444} m_Layer: 0 m_Name: Bedroom Task m_TagString: Untagged @@ -315262,6 +315263,22 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2057524444 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2057524442} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5400e1a957408e941ba95a252e2d15b0, type: 3} + m_Name: + m_EditorClassIdentifier: + trashCollected: 0 + trashToUnlock: 10 + door: {fileID: 61007070} + doorInteractable: {fileID: 61007073} --- !u!43 &2057535447 Mesh: m_ObjectHideFlags: 0 diff --git a/Game/Assets/Scripts/BedroomTask.cs b/Game/Assets/Scripts/BedroomTask.cs index 395a40d..f054204 100644 --- a/Game/Assets/Scripts/BedroomTask.cs +++ b/Game/Assets/Scripts/BedroomTask.cs @@ -4,28 +4,48 @@ Date: 3/2/25 Description: To track if cleaning/exploring bedroom task is done before allowing player to open door */ - using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.ProBuilder.Shapes; using UnityEngine.XR.Interaction.Toolkit.Interactables; public class BedroomTask : MonoBehaviour { + public int trashCollected = 0; + public int trashToUnlock = 1; public GameObject door; public XRGrabInteractable doorInteractable; - - private bool taskCompleted = false; // Start is called before the first frame update void Start() { - + if (door != null) + { + doorInteractable = door.GetComponent(); + if (doorInteractable != null) + { + doorInteractable.enabled = false; + Debug.Log("Room is not cleaned! Door is locked"); + } + } } - // Update is called once per frame - void Update() + public void CollectTrash() { - + trashCollected++; + Debug.Log("Trash Collected: " + trashCollected + "/" + trashToUnlock); + + if (trashCollected >= trashToUnlock) + { + UnlockDoor(); + Debug.Log("Cleaning task completed! Unlocking door..."); + } + } + + private void UnlockDoor() + { + doorInteractable.enabled = true; + Debug.Log("Room is cleaned! Door unlocked"); } } diff --git a/Game/Assets/Scripts/Trash.cs b/Game/Assets/Scripts/Trash.cs index e3c8083..85d5e9c 100644 --- a/Game/Assets/Scripts/Trash.cs +++ b/Game/Assets/Scripts/Trash.cs @@ -10,14 +10,14 @@ using UnityEngine; public class Trash : MonoBehaviour { - public static int trashCollected = 0; + private BedroomTask bedroomTask; private void OnTriggerEnter(Collider other) { - if (other.gameObject.CompareTag("TrashBin")) + if (other.CompareTag("TrashBin")) { - trashCollected++; - Debug.Log("Trash thrown in the bin! Count: " + trashCollected); + bedroomTask.CollectTrash(); + Debug.Log("Trash thrown in the bin! Count: " + bedroomTask.trashCollected); Destroy(gameObject); } }