- Home /
Audio stops playing after releasing my Mouse Button and pressing another key
Hi, I have a 5-second audio that I want to play if I click my left mouse button. However, whenever I try to press another key in my keyboard, the sounds stop playing. It does not finish playing the audio.
Thanks in advance :) Here's my code:
public AudioClip mySound1;
AudioSource audio;
// Use this for initialization
void Start () {
audio = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1")) {
audio.PlayOneShot (mySound1);
}
Answer by b1gry4n · Oct 20, 2016 at 06:38 PM
An audiosource can only play 1 sound at a time. You need to create a second audio source if you want to overlay the sounds.
wheres the rest of the code?
Answer by ryekis · Oct 21, 2016 at 07:27 AM
Ooh..okay thanks..I've attached this script to the FPS controller which also has the same audio source..:))
Your answer
![](https://koobas.hobune.stream/wayback/20220612095045im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to switch Audiosource without stacking by an input? 0 Answers
Problems combining Audio triggers, PlayOneShot and Audio Arrays 1 Answer
2nd Audio Clip Not Playing 0 Answers
Play Audio on Object click? 2 Answers
Why PlayOneShot is not working? C# 1 Answer