Language

How to play sound when player walks through box collider trigger?

Ok so I want it to play a door creak sound when you open the door so I made a script and attached it to the same box collider (trigger is on) that opens the door but my script isn't working. Heres the script

There's a few things I see wrong here - You are destroying something, probably the audio source, instantly after getting it to play. Instantly wouldn't really describe it, it basically doesn't even play. You should pass the destroy function the time parameter if you want it to wait a little bit so it doesn't cut off the audio.

The next thing is Destroy is called as a method/function, and does not have any variables that you can access, so Destroy.anything will not work. It's used like this:

Destroy(object, time_delay);

Where 'object' can be a component/game object/etc, time delay is self explanatory. So in your case, Destroy(audio)