• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by squishy89x · May 09, 2017 at 05:46 AM · audioaudiosourceaudioclipaudiolisteneraudio listener

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);

 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

114 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What causes weird cracking/popping sound when playing 3d sound 1 Answer

Can't get an AudioSource to play on awake 2 Answers

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

Audio not playing when conditions are met. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges