Click To Start Animation

I am creating an menu in witch the camera flies into the scene over the terrain. I then want the camera to move to an other part of the map when when I click the play button. The play button is a 3d text with a colider box on it and I have to seperate Animations for the the FlyIn and LevelSelect. This is the code I have on the collider.

    var playing : boolean = false;

function OnMouseEnter() { //Change the text color of the test renderer.material.color = Color.red; }

function OnMouseExit() { //Change the text color of the test renderer.material.color = Color.white; }

function OnMouseDown()
 {
    if (!playing) {
      playing = true;
      animation.Play ("LevelSelect");
      yield WaitForSeconds(animation.clip.length);
      playing = false;
   }
 }

What am I not doing?

OnMouseDown cannot be used as a Coroutine. You should split that into two seperate functions, like this-

function OnMouseDown()
{
   if (!playing) {
      PlayAnimation("LevelSelect");
   }
}

function PlayAnimation(animName : String)
{
    playing = true;
    animation.Play (animName);
    yield WaitForSeconds(animation.clip.length);
    playing = false;
}

This way, you start a coroutine with the call to ‘PlayAnimation’, and it will handle the WaitForSeconds properly.