Audio won't play on hit

Hello. I’m trying to play audio when the character dies. Here is what I have.

    private var finish = false;
       
    function OnControllerColliderHit(hit : ControllerColliderHit) { 
       
        if(hit.gameObject.tag == "KILL"){ 

        finish = true;
    }
    
    	if(finish){

        Death();
       	}
    }

    function Death(){
   
       	Camera.main.SendMessage("fadeOut");
   
       	audio.Play();
   
       	LevelLoad();
}

   function LevelLoad(){

   	yield WaitForSeconds(2);
  
    Application.LoadLevel(1);
   
    finish = false;
}

I’ve tried moving audio.Play() to different parts of this code but it won’t work. Thanks in advance.

OnControllerColliderHit happens all the time due to the collision of the character with the ground, and this is calling Play each Update after the character hits the KILL object. Change your code a little to ensure that Death will be called only once:

private var finish = false;

function OnControllerColliderHit(hit : ControllerColliderHit) { 
    if (hit.gameObject.tag == "KILL" && finish == false){ 
        finish = true;
        Death();
    }
}

This will also avoid calling LevelLoad multiple times, what can cause a disaster (it’s a coroutine, and each call to LevelLoad starts a new instance of this coroutine).