diff --git a/Game/Assets/Scenes/House.unity b/Game/Assets/Scenes/House.unity index a5d9add..7d34c49 100644 --- a/Game/Assets/Scenes/House.unity +++ b/Game/Assets/Scenes/House.unity @@ -138804,6 +138804,9 @@ MonoBehaviour: door: {fileID: 214241217} lockedDoorUI: {fileID: 1786768887} unlockedDoorUI: {fileID: 1654433218} + audioSource: {fileID: 1898819871} + lockedSound: {fileID: 8300000, guid: 66df24e59b960964d967e61a34192cc5, type: 3} + unlockedSound: {fileID: 8300000, guid: 52fae69899b3fc24694a0f879a7d821a, type: 3} --- !u!43 &2060072005 Mesh: m_ObjectHideFlags: 0 diff --git a/Game/Assets/Scripts/BedroomTask.cs b/Game/Assets/Scripts/BedroomTask.cs index a702ba0..dfa2d3c 100644 --- a/Game/Assets/Scripts/BedroomTask.cs +++ b/Game/Assets/Scripts/BedroomTask.cs @@ -34,6 +34,11 @@ public class BedroomTask : MonoBehaviour // Defines UI references public GameObject lockedDoorUI; public GameObject unlockedDoorUI; + + // Defines Audio References + public AudioSource audioSource; + public AudioClip lockedSound; + public AudioClip unlockedSound; void Start() { @@ -75,6 +80,12 @@ public class BedroomTask : MonoBehaviour // If player has collected/thrown required amount of trash if (trashCollected >= trashRequired) { + // Play sound only if no other sound is currently playing + if (!audioSource.isPlaying) + { + audioSource.PlayOneShot(unlockedSound); + } + // Call unlocking door function UnlockDoor(); } @@ -138,6 +149,12 @@ public class BedroomTask : MonoBehaviour // Show the locked door UI lockedDoorUI.SetActive(true); + // Play sound only if no other sound is currently playing + if (!audioSource.isPlaying) + { + audioSource.PlayOneShot(lockedSound); + } + // Call the function to hide the UI after delay StartCoroutine(HideMessageAfterSeconds(lockedDoorUI, 5f)); Debug.Log("The door is locked! Clean the room first.");