How do I play a sound when player enters room?

(New with Unity! :slight_smile: )

I would like to play a sound when the player enters a room and let it end when the player leave the room.

Two options comes to mind.

Option #1

The room has a collider that is a trigger, when a player enters the room(OnTriggerEnter) an associated AudioClip is played. When the player exits the room(OnTriggerExit) the AudioClip is stopped.

Note: You could use OnTriggerStay to evaluate if the player is in the room and continue to play the AudioClip, OnTriggerExit to stop the AudioClip

Option #2

You create a collider and place it where the door is. When a player go through the collider(again still a trigger) it will set a boolean variable to true indicating the player is in the room and to play the AudioClip as mentioned above. When the player goes through the trigger again, the boolean(isInRoom maybe) is evaluated and determined to be true, set it to false and stop the AudioClip.

Disclaimer: UA is not a script writing service, give it a go and report back and we could continue to try and help with specific questions. Design questions should really go to the forums for a continuous discussion.