- Home /
audio.Play Help :S
I have been at this for hours and I am really confused about what the problem is.
I have a rigidbody that I want to meow when it hits a certain object. Now this rigidbody also has a point value on it, and my script for adding points works perfectly. So I am not sure why it is not playing the sound. I have tried all sorts of variations of different kind of scripts. Have moved around audio source and script between the rigidbody and the other object. But no sound.
var meow : AudioClip;
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Player"){
audio.PlayOneShot(meow);
ScoreSystem.myScore += 1;
Destroy(gameObject,0.0);
}
Please help :)
Thanks
Did you make sure that there is an audio source on the object (This might sound dumb, but sometimes it happens).
Check your audio listener in the main camera to make sure that its working.
As stated I have audio source and have moved it around.
I have another sound that plays on away that works fine, so listener works.
it might be from the trigger, recheck if you have set the tag of the player to "player" , also check the audio volume, it must be some tiny reason..
I have maxed the volume on the source and have even tried using a collision script. It really seems as tho the listener is not picking it up for some reason. If my main camera is a child of an object, would that cause an issue?
tried moving the listener to the parent object, still no difference.
Answer by Hyperion · Jun 11, 2013 at 07:21 PM
If you're still having problems, I use a different method that ALWAYS works: in your code instead of doing playoneshot , I do
AudioSource.PlayClipAtPoint(sound, transform.position);
I can get more specific if you want me to... In fact, here's an example:
//vars
var explosion : Transform;
var blast : AudioClip;
function OnTriggerEnter(hit: Collider)
{
if (hit.gameObject.tag=="projectile")
{
Destroy(hit.gameObject);
Instantiate(explosion,transform.position,Quaternion.identity); //Quaternion.identity takes angle of object
AudioSource.PlayClipAtPoint(blast, transform.position);
Destroy(gameObject);
}
}
-Hyperion
By god that did it! your my savior. Solved a problem I havent been able to figure out for 3 days. Thank you! Now I can get back to making my game lol..
Answer by sixShOOter50o0 · Jun 11, 2013 at 06:38 PM
change the script around a bit and make the var like this:
var meow : GameObject;
and then create an empty and assign the sound that you want, after make a prefab and drop the empty that you made in the prefab and erase the empty, after that click on whatever you assigned the script to and drop the prefab on the "meow" game object and see if that will work.