Quantcast
Channel: Latest Questions by Meriodoc
Viewing all articles
Browse latest Browse all 20

How to prevent more mouse clicks that trigger sound.

$
0
0
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); } }

Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>