Disabling a script inside a coroutine(look at my comment below)?

Hi I wrote a script to play a sound after the if statement activates, but nothing happens. I’ve tried a lot of different things. Here is the script I’m using:

using UnityEngine;
using System.Collections;

public class TimerScript : MonoBehaviour 
{
	public GUIText clockTime;
	public GUIText loseMessage;

	public GameObject rift;
	public GameObject tryAgainButton;
	public GameObject returnButton;

	public Rigidbody kineticBody;

	private float timeLeft;

	public AudioClip[] loseSound;

	void Start ()
	{
		kineticBody = GetComponent<Rigidbody> ();
		timeLeft = 30;
		clockTime.text = "Time: 00:" + timeLeft.ToString();
		loseMessage.text = "";
	}

	void Update ()
	{
		timeLeft -= Time.smoothDeltaTime;
		clockTime.text = "Time: 00:" + timeLeft.ToString ();
		if (timeLeft <= 0) 
		{
			loseMessage.text = "You Failed!";
			clockTime.text = "Time: 00:00";
			tryAgainButton.SetActive(true);
			returnButton.SetActive(true);
			kineticBody.isKinematic = true;
			rift.SetActive(false);
			PlaySound(0);

		}
	}

	void PlaySound (int noise)
	{
		audio.clip = loseSound[noise];
		audio.Play ();
	}
}

I’m new to Unity so I’m not sure what I’m doing wrong.

It’s probably 1 of 2 things or both. 1) make sure you assigned a sound clip to the loseSound array in the Inspector. 2) Your Update() method is going to run every frame, so once the timer runs out, you’re going to call PlaySound every frame which will restart your clip to the first sample every frame. You can fix this by wrapping it with a “if (!audio.isPlaying)” check before calling PlaySound, or you could add a new flag “gameOver” which you set to true at line 40 and test that it is false at line 31.