need to play audio once and disable button while playing

I’m using NGUI and want to play a audio clip after hitting a button. But I want it to disable that button during the playing otherwise if you keep pressing the button over and over again you get the clip playing over itself. Also if I hit any other button I’d like the audio to stop playing … here is the script I’m working with

using UnityEngine;

///


/// Plays the specified sound.
///

[AddComponentMenu(“NGUI/Interaction/Button Sound”)]
public class UIButtonSound : MonoBehaviour
{
public enum Trigger
{
OnClick,
OnMouseOver,
OnMouseOut,
OnPress,
OnRelease,
}

public AudioClip audioClip;
public Trigger trigger = Trigger.OnClick;
public float volume = 1f;

void OnHover (bool isOver)
{
	if (enabled && ((isOver && trigger == Trigger.OnMouseOver) || (!isOver && trigger == Trigger.OnMouseOut)))
	{
		NGUITools.PlaySound(audioClip, volume);
	}
}

void OnPress (bool isPressed)
{
	if (enabled && ((isPressed && trigger == Trigger.OnPress) || (!isPressed && trigger == Trigger.OnRelease)))
	{
		NGUITools.PlaySound(audioClip, volume);
	}
}

void OnClick ()
{
	if (enabled && trigger == Trigger.OnClick)
	{
		NGUITools.PlaySound(audioClip, volume);
	}
}

}

Why not use the unity audio source and use the isPlaying() to check? :confused: would that work for you?

Did you ever find an answer to your question?

You could use a coroutine to wait for the duration of the audioclip. Something like this…

public void OnClick()
 {
    StartCoroutine(PlayAudioAndDisableButton());
 }

 private IEnumerator PlayAudioAndDisableButton()
 {
     float duration = audioClip.length;
     //disable button here
     //play audioclip
     yield return new WaitForSeconds(duration);
     //enable button here
 }