game: misc (bedroom task isnt fully working yet)

This commit is contained in:
rezazfn 2025-02-04 12:03:44 +08:00
parent 135579f366
commit d9741b0290
3 changed files with 48 additions and 11 deletions

View file

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

View file

@ -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()
{
}
// Update is called once per frame
void Update()
if (door != null)
{
doorInteractable = door.GetComponent<XRGrabInteractable>();
if (doorInteractable != null)
{
doorInteractable.enabled = false;
Debug.Log("Room is not cleaned! Door is locked");
}
}
}
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");
}
}

View file

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