My problem is that when i click on an object multiple times the sound just keeps repeating/echoing. How can i set the co-routine or function to wait until clip and animation is finished playing before allowing another mouse click?
Any help will be appreciated. Thank you!
Here is my snippet:
using UnityEngine;
using System.Collections;
public class A_LetterScript : MonoBehaviour {
private Animator animator;
private int State = 0;
private AudioSource audioSource;
public AudioClip aPageVoice;
void Start ()
{
animator = this.GetComponent();
animator.SetInteger ("State", 0);
}
private void OnMouseDown()
{
Debug.Log("clicked.");
animator.SetInteger ("State", 1);
StartCoroutine ("Sound");
StartCoroutine ("Wait");
}
IEnumerator Wait ()
{
yield return new WaitForSeconds (5.0f);
animator.SetInteger ("State", 0);
}
IEnumerator Sound ()
{
//this is to sync my sound with my animation
yield return new WaitForSeconds(1.2f);
//this is to set my volume
audio.PlayOneShot(aPageVoice, 0.7F);
}
}
↧