- Home /
Audio Trigger Problems
Hello. I have recently written (with help from another question (: ) a script that deactivates gameobjects when a trigger is hit (for a 3.X version of unity). I have added a sound and audio source to the object and added a play audio in my script. The audio does not play. Here is the script.
#pragma strict
var Item : GameObject;
var Sound : AudioClip;
function Start () {
Item.active=true;
}
function OnTriggerEnter(){
audio.PlayOneShot(Sound);
Item.SetActiveRecursively(false);
}
Answer by RyanZimmerman87 · Sep 07, 2013 at 01:25 AM
Have you assigned the sound file to both the Audio Source and Audio Clip in the inspector?
And are you sure the OnTriggerEnter() is working? You might want to set up some debug text to verify the event is working.
If you did all that right my only guess is that your SetActiveRecursively could be causing the problem. Or that your audio source is not set to be large enough to reach your Audio Listener.
You could try increasing the Audio Source "Min Distance" and "Max Distance" variables to ensure that your source will in fact reach your listener.
Also I have to ask why are you not using Unity 4.X?
They have changed the way the gameObjects are handled so SetActiveRecursively is no longer the way to go in 4.X maybe it's not that great in 3.X either?
You may also want to try it without the :
Item.SetActiveRecursively(false);
That could cause the sound to not play as well possibly, I've never used SetActiveRecursively though so I'm just speculating.
Honestly, i wish I could switch but I can't because I have a few other projects in progress that use SetActiveRecursively and, I have to have this game by tomorrow. Also, The OnTriggerEnter does work.
Did you try all the stuff I suggested and still doesn't work?
I mean you should try not using that to see if that is the problem. I'm trying to help you isolate the problem since I'm not sure what is causing it.
Your answer
Follow this Question
Related Questions
Trigger to play music needs to check if the same music is already playing 1 Answer
Play random sound on NPC when trigger enter 1 Answer
Cannot get trigger sound to play for collectibles 1 Answer
Script to trigger all audio playing to stop, and play a different audio? 1 Answer
GetComponent().Play(); Question(s) 2 Answers