- Home /
How to emit an audioClip on Collision
I need to know how to emit an one shot audio clip on collision. I want to emit a audio clip when my FirstPersonController collides with a box collider, heres the script im using right now(script bellow), its not working, so if you can add on to so it will work thats good or if you want to give me a new one thats also good, im new to scripting though so giving me a link to somwhere might not help me that well. Please Help.
var voiceSound : AudioClip;
function OnCollisionEnter (collision : Collision){
audio.PlayOneShot(voiceSound);
Do you have an AudioSource
called audio
? Have you set voiceSound
to an actual clip in the inspector?
You don't necessarily need an audioSource named audio. If you add an audioSource component in the editor, audio.whatever will automaticaly access it.
start by adding a debug log inside the OnCollisionEnter function:
Debug.Log("Collider Hit");
to see if the collision is the problem, or the audio
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to play Audio Once if enemy has enterd a trigger 1 Answer
Play audio only once in trigger collision entry? 1 Answer
How to emit a sound on specific collision. 1 Answer
Can you make this work? (Click Collider = Make Sound) 2 Answers