How do you trigger an audio clip when two game objects collide with each other?
I was just wondering if anyone knows a step by step way using c#. I'm finding the scripting API a little confusing, considering I'm quite new to Unity.
I still don't have a code because I'm fiddling around with various tutorials, with no luck!
Thanks in advance !
Hi Supahtricia, There is an event called OnColliderEnter and OnColliderStay within the Collider Class object, these events are called when as the names state on enter (a collision) and on stay is called repeatedly as long as these 2 colliders are intersecting, you can call a sound to play at this time, if you are using OnStay remember to use a boolean check to flag that you have played the sound otherwise it will play the clip again every update. see this thread for info on playing an audio clip;
http://answers.unity3d.com/questions/12546/playing-audio-clip.html
and these for the Collider objects;
http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html http://docs.unity3d.com/ScriptReference/Collider.OnCollisionStay.html
Hope that helps.
Your answer
Follow this Question
Related Questions
Trigger detects player collision and play specific audio from array 1 Answer
How do you make audio play after GameObject Collides with another Game Object? PLZ REPLY QUICK 0 Answers
Trouble Respawning objects after colliding with trigger 0 Answers
Finding contact point in OnTriggerEnter2D? 0 Answers
Implement particle scattering after collision for a Collider/Rigidbody/Trigger GameObject 0 Answers