The audio listener that I have attached to this object won’t play when told. Can someone help me resolve this please? Picture of workspace included for ref. Thanks!
You call Destroy(gameObject) just after calling audio.Play(). Destroying the game object will also destroy all attached components – including the AudioSource.
You can try using PlayClipAtPoint instead.
What exactly is the correct way to use that in an OnTriggerEnter. Cuz I keep getting a long gibberishy error message.
Can someone please help? ?
Why don’t you paste the code or at least the error message? Give us something to work with, here!
There is a source example in the link given.
Cheers,
-Jon
Like freyr said, don’t Destroy the GameObject right away… give it a couple seconds to let the audio play… Destroy (gameObject, 5).
It’s kinda a thing that’s supposed to dissappear when you touch it. As soon as you touch it. When I try to use the sourcecode example from the page it says:
“Assets/Working Assets/scripts/Rings.js(9) Error BCE0023: No Appropriate Version of ‘UnityEngine.AudioSource.PlayClipAtPoint’ for the argument ‘(System.type.UnityEngine.Vector3)’ was found”
So in the original example it also has a audio clip which it gives to the function. Otherwise the function wouldn’t know what sound to play right?
So you want to also pass in that sound.
So first you expose a reference to a clip outside of that function, then you tell it to play that clip just before calling Destroy. Also in the inspector you of course have to drag the AudioClip on the clip property you just exposed.
var clip : AudioClip;
inside the function
{
....
AudioSource.PlayClipAtPoint(clip, transform.position);
}
Ah. Smack Forehead Sound Effect Thanks Joe.