looping an animation until music stops

hi everyone…

i have an animated character which dances around 3 seconds…

and i have an audio file which runs for 24 seconds…

my idea is to loop the animation until the music stops playing…

so… it both the animation and the audio file stops at the same time…

and i have no idea how to create this…

please help…

thank you…

if (!audio.isPlaying)
animation.Stop();

I assume you have it all set up to start the animation and music. This will be checking if the audio is playing something. If there is no audio playing on this object the animation stops.

In the case, the audio source is not in the character you would have to fetch like so:

var go : GameObject;

function Start(){
   go = GameObject.Find("Dancer");}

function Update(){
  if(!audio.isPlaying)
    go.animation.Stop();
}

This is attached to the object playing the music.