I tasked myself from the list of tasks to complete a method of playing audio clips when a player enters a set area. Though there may be different ways of completing this task. I first created a cube, then removed everything but the collider. And then readjust it to fit the target area, or just in front of the door if you want the audio to play when they enter. For example,
Then on the inspector of this collider, I created a new script, and wrote the following,
It basically just says, OnTriggerEnter(As some one touches the collider), set the GameObject as active. The game object is a variable, that can be selected by dragging it into the script by the inspector of the object the script is inside of, the object we are selecting in this case, is the Audio Cube, as I named it. The audio cube is what plays the audio, (see the bottom, Audio Cube)
The inspector below is from the Audio Cube, if you look at the top right the active box is unchecked. In in the Audio source component, we have a audio clip selected(the top box in the Audio Source), and the “Play On Wake” is set active. So as the cube is set active by the previously shown script, it will play the audio on wake, or as it is set active. And the script will do this once a player collides with the collider.
My method is only one of many, it is possible to put the audio source and the collider together and use only scripting, not two cubes. I’m yet to learn how to…