game: tried audio and it worksss

This commit is contained in:
rezazfn 2025-02-07 16:35:46 +08:00
parent fa8ca2a41e
commit 29fe60bb58
2 changed files with 20 additions and 0 deletions

View file

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

View file

@ -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.");