I just want to play a sound (would be nice if the Audio thing had a Play event), anyway I made a little script, added it to my object. I can see the script and all in the Animation editor ok. I add an Animation Event where I want the sound to play. Note I have no compiler errors.
So it brings up the 'Edit Animation Event' dialog, but there are no functions to select! The only 'choice' I have is (no function selected). My script looks a lot like the one in the manual's example. It's JS:
private var sound : AudioSource;
function Start()
{
sound = GetComponent (AudioSource);
}
function Play ()
{
sound.Play();
}
I tested what you describe and it worked perfectly fine. I cannot guess at what you have done wrong, but something about your description of your setup is missing. Maybe try a fresh scene and test what exactly you’re doing. I created a cube, added a sound and attached the script “function Play(){audio.Play();}” I created an animation in the Animation window that went from position x = 0 at frame 0 to position x = 200 at frame 40. I added an AnimationEvent at frame 20 and I was able to set the function for the Event in the dialog to Play().
I think there is a bug in Unity where you cannot select any function if the gameObject has children. You have to delete all its children or move them select a method for an animation event and then move back the gameObject children. That’s how I fixed my problem.