- Home /
Sound wont play when triggered (javascript)
What I want to happen is that whenever an object passes over the empty objects with 2d box colliders titled - left, right, and middle - a sound will be played. My collisions work (I have tested them with Debug.Log) but my sound wont play. My script is
var beep : AudioClip;
function OnTriggerEnter2D() {
audio.PlayOneShot(beep);
}
I dragged the sound into the inspector, and to my knowledge this should work. When I run my game, an error appears that says
You probably need to add a AudioSource to the game object "Right". Or your script needs to check if the component is attached before using it. UnityEngine.AudioSource.PlayOneShot (UnityEngine.AudioClip clip) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/AudioBindings.cs:499) Beep.OnTriggerEnter2D () (at Assets/Scripts/Audio/Beep.js:6) It says I need to attach an Audio Source, but to my knoweledge, I shouldn't have to. If I do need to attach an audio source, how to I disable all of the complex 3d capabilities and get it to work.MissingComponentException: There is no 'AudioSource' attached to the "Right" game object, but a script is trying to access it.
The error says you do. You probably don't need to touch the 3D sound parts
Answer by Yofurioso · Mar 18, 2014 at 12:52 PM
You should attach an Audio Source to the object and disable the "3D sound" option on the sound clip, like so:
Your answer
Follow this Question
Related Questions
WWW Audio and PlayOneShot: Playing the same AudioClip Twice Cuts off First Instance 1 Answer
2d PlayAudioOneShot inconsistent behavior 0 Answers
Can't get PlayOneShot() or Play() to work 1 Answer
JavaScript Play Audiosource Problem 1 Answer
Playing many audioclips with PlayOneShot causes all sound to cut out. 0 Answers