game(scripts): polished bedroom task and brush teeth task to update gamemanager

This commit is contained in:
rezazfn 2025-02-10 00:56:32 +08:00
parent a3a8eaf852
commit d8d40f1aa5
4 changed files with 55 additions and 6 deletions

View file

@ -86823,10 +86823,18 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 745726886} m_TransformParent: {fileID: 745726886}
m_Modifications: m_Modifications:
- target: {fileID: 806528791475834742, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
propertyPath: audioSource
value:
objectReference: {fileID: 1898819871}
- target: {fileID: 806528791475834742, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3} - target: {fileID: 806528791475834742, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
propertyPath: progressBar propertyPath: progressBar
value: value:
objectReference: {fileID: 1902891356} objectReference: {fileID: 1902891356}
- target: {fileID: 806528791475834742, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
propertyPath: brushingSound
value:
objectReference: {fileID: 8300000, guid: 9cf02b0277ad0324389ae25a9fefe8ba, type: 3}
- target: {fileID: 3017716152663212623, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3} - target: {fileID: 3017716152663212623, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: -0.184021 value: -0.184021
@ -86873,7 +86881,7 @@ PrefabInstance:
objectReference: {fileID: 430002287} objectReference: {fileID: 430002287}
- target: {fileID: 3408018161587624474, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3} - target: {fileID: 3408018161587624474, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
propertyPath: m_VersionIndex propertyPath: m_VersionIndex
value: 1679 value: 1685
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5470122699805207955, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3} - target: {fileID: 5470122699805207955, guid: 519c364a8a1b96b428f69317d2cfb87f, type: 3}
propertyPath: m_Mesh propertyPath: m_Mesh

View file

@ -14,6 +14,8 @@ using UnityEngine.XR.Interaction.Toolkit;
public class BedroomTask : MonoBehaviour public class BedroomTask : MonoBehaviour
{ {
private GameManager gameManager;
[Header("Task Requirement Values")] [Header("Task Requirement Values")]
// To track how much trash has been collected so far // To track how much trash has been collected so far
public int trashCollected = 0; public int trashCollected = 0;
@ -99,7 +101,7 @@ public class BedroomTask : MonoBehaviour
// If player has collected/thrown required amount of trash // If player has collected/thrown required amount of trash
if (trashCollected >= trashRequired) if (trashCollected >= trashRequired)
{ {
Debug.Log("Trash requirement met! Starting sound sequence..."); GameManager.Instance.BedroomTaskComplete();
// Call unlocking door function/sequence // Call unlocking door function/sequence
StartCoroutine(PlaySoundSequence()); StartCoroutine(PlaySoundSequence());
@ -147,6 +149,12 @@ public class BedroomTask : MonoBehaviour
doorCollider.enabled = true; doorCollider.enabled = true;
} }
// Play sound only if no other sound is currently playing
if (!audioSource.isPlaying)
{
audioSource.PlayOneShot(unlockedSound);
}
// Show the unlocked door UI // Show the unlocked door UI
unlockedDoorUI.SetActive(true); unlockedDoorUI.SetActive(true);
@ -185,8 +193,6 @@ public class BedroomTask : MonoBehaviour
private IEnumerator PlaySoundSequence() private IEnumerator PlaySoundSequence()
{ {
Debug.Log("Starting PlaySoundSequence...");
// Play footsteps of parents walking away // Play footsteps of parents walking away
audioSource.PlayOneShot(footstepsSound); audioSource.PlayOneShot(footstepsSound);
yield return new WaitForSeconds(footstepsSound.length); yield return new WaitForSeconds(footstepsSound.length);
@ -197,6 +203,7 @@ public class BedroomTask : MonoBehaviour
// Unlocks the door after the clips and update the story // Unlocks the door after the clips and update the story
UnlockDoor(); UnlockDoor();
storyText.text = "They finally left... just as soon as I finished cleaning. I can leave the room now."; storyText.text = "They finally left... just as soon as I finished cleaning. I can leave the room now.";
storyPanelUI.SetActive(true); storyPanelUI.SetActive(true);
StartCoroutine(HideMessageAfterSeconds(storyPanelUI, 10f)); StartCoroutine(HideMessageAfterSeconds(storyPanelUI, 10f));

View file

@ -1,5 +1,5 @@
/* /*
Author: Wai Lam Author: Wai Lam & Reza
Date: 27/1/25 Date: 27/1/25
Description: Bathroom interaction Description: Bathroom interaction
*/ */
@ -14,13 +14,17 @@ using UnityEngine.XR.Interaction.Toolkit.Interactors;
public class BrushTeeth : MonoBehaviour public class BrushTeeth : MonoBehaviour
{ {
public PostProcessingManager postProcessingManager; private GameManager gameManager;
public Slider progressBar; // Reference to the Slider (progress bar) public Slider progressBar; // Reference to the Slider (progress bar)
public float progressTime = 5f; // Time for the progress bar to complete public float progressTime = 5f; // Time for the progress bar to complete
private XRGrabInteractable grabInteractable; private XRGrabInteractable grabInteractable;
private float timer = 0f; private float timer = 0f;
private bool isGrabbing = false; private bool isGrabbing = false;
// Audio References
public AudioSource audioSource;
public AudioClip brushingSound;
void Start() void Start()
{ {
@ -67,6 +71,17 @@ public class BrushTeeth : MonoBehaviour
progressBar.value = 0f; progressBar.value = 0f;
timer = 0f; timer = 0f;
isGrabbing = true; isGrabbing = true;
// Play brushing sound while toothbrush is grabbed, plays only if it isn't playing already
if (!audioSource.isPlaying)
{
audioSource.clip = brushingSound;
// Loops the sound for as long as the toothbrush is held; allows editable progress time
audioSource.loop = true;
audioSource.Play();
}
} }
private void OnRelease(SelectExitEventArgs args) private void OnRelease(SelectExitEventArgs args)
@ -75,12 +90,26 @@ public class BrushTeeth : MonoBehaviour
progressBar.gameObject.SetActive(false); progressBar.gameObject.SetActive(false);
isGrabbing = false; isGrabbing = false;
timer = 0f; timer = 0f;
// Stop the brushing sound when the toothbrush is released
if (audioSource.isPlaying)
{
audioSource.Stop();
}
} }
private void CompleteProgress() private void CompleteProgress()
{ {
progressBar.gameObject.SetActive(false); progressBar.gameObject.SetActive(false);
isGrabbing = false; isGrabbing = false;
// Stop the brushing sound when the task is completed
if (audioSource.isPlaying)
{
audioSource.Stop();
}
GameManager.Instance.BrushTeethTaskComplete();
Debug.Log("Progress completed!"); Debug.Log("Progress completed!");
} }

View file

@ -65,4 +65,9 @@ public class GameManager : MonoBehaviour
{ {
bedroomCleaned = true; bedroomCleaned = true;
} }
public void BrushTeethTaskComplete()
{
teethBrushed = true;
}
} }