audio trigger question/help

i have no experience with programming. I can make my levels in the unity engine but i need to make a now a simple audio trigger. I want I walk in an invisible cube or someting than an audioplay plays but when i walk outside that area the audio clip stops playing.

Could somebody help me on this? Highly appreciate!

fundi

You can make an object with a box collider. Check the “isTrigger” option. Add an audio source to the same object and an audio listener to the camera (if not added by default).

Add a script to that object with the following code:

function OnTriggerEnter (Collider other) 
	{
		audio.Play();
	}

function OnTriggerExit (Collider other) 
	{
		audio.Stop();
	}

That should work. Please note thats it’s completely untested.

i got it working :wink:

there is just a slide typo: it should be

function OnTriggerEnter (other : Collider)
{
audio.Play();
}

function OnTriggerExit (other : Collider)
{
audio.Stop();
}

[/code]

Sorry, I copy pasted from my C# code :slight_smile:

Glad to see it work. I feel your happiness :slight_smile: