This is related to the 'footstep sounds when walking' question which has helped me a lot until now. I'm trying to make it so that on an animation event a function is called which plays a sound effect (be it a footstep, a drip sound, and so on). I would also like to trigger something like a GUITexture which will show an animation of the event (such as ripples expanding) but I haven't got that far yet.
I know that to edit the animation on an imported model I will have to duplicate the animation - i'll look into that later, although Rune's post here seems to have everything I need - so at the moment i'm testing it on a simple Unity sphere 'dripping' from a shower head.
On the frame where the sphere reaches the ground I have an animation event that calls this function:
var audioVolume = 1.0;
var collisionSoundEffect : AudioClip;
function playSound(){
Debug.Log("Animation event called");
audio.volume = audioVolume;
audio.clip = collisionSoundEffect;
audio.Play();
// Code to show GUI animation
otherscript = GameObject.Find("dripGUI").GetComponent("guiAnim");
otherscript.dripPlaying = true;
}
@script RequireComponent(AudioSource)
It works but I only hear the sound when I am facing the sphere, despite having the sound set to '3D sound'. It becomes difficult to hear the sound at all when I get close to the sphere as it drops past the camera too quickly. Also the sound itself is very quiet. Changing the volume doesn't seem to do anything, although the Rolloff factor works.
EDIT - It's not just that I can't hear the sound; the animation of the sphere, and the related GUITexture animation from my other question, don't play either unless the sphere is in view of my camera.
I had a similar problem earlier when I used the 2D Gameplay Tutorial method (OnTriggerEnter). It worked fine on the PC, but the sound was very quiet on NPCs (I know the audio source on the PC would be closer to the camera's audio listener but it was still REALLY quiet on NPCs).
I intend to have a few of these audio sources which play a sound, (maybe trigger an in-game animation), and trigger a GUI animation. I want to use animation events because not all of them are triggered by a collision, and it would be good to have one script for all that allows me to set a sound effect, in-game animation (if need), and a gui animation to play.
If anyone can offer any suggestions, i'd really appreciate it.
Thank you for your time.