How to stop current audio before another audio starts?
I have a game object with audio on it on click however when the scene opens there is audio already playing. If you click the game object to fast the other audio starts playing and there is an overlap. I've tried numerous solutions to no prevail. Does anyone have a suggestion? Here is my current code.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.Audio;
//var rock : GameObject; [RequireComponent(typeof(AudioSource))]
public class TrexMouthController : MonoBehaviour {
public GameObject feed;
public GameObject weight;
public GameObject height;
public GameObject hold;
public GameObject length;
public AudioClip mymouthclip;
public AudioClip[] audioSourcesToIgnore;
AudioSource audio;
// Use this for initialization
void Start () {
audio = GetComponent<AudioSource> ();
}
// Update is called once per frame
void Update () {
}
// Event Trigger Handlers
public void CubeClicked()
{
Debug.Log ("MouthClicked");
feed.SetActive (true);
weight.SetActive (false);
length.SetActive (false);
height.SetActive (false);
hold.SetActive (false);
audio.PlayOneShot (mymouthclip, 0.7F);
}
}
Your answer
Follow this Question
Related Questions
How to make the player not hear a specific audio source 0 Answers
Trying to use derive pitch and db from realtime microphone input 0 Answers
I want the audio to play when the player nears the object, but fade away when they walk away. 0 Answers
Audio not playing when conditions are met. 0 Answers
Trying to use derive pitch and db from realtime microphone input 0 Answers