- Home /
Audio stops playing to restart
So, I'm making a game about a ball that every time that it does a dash, a sound is played. This soud repeats a lot of times and if it starts to play again while it's still playing the sound stops and restart. is there anyway I can make the sound don't stop play to play again? Sorry for my bad english, I'm Brazillian. Here is the code I'm using to play the audio: public AudioSource dash;
private void Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
if (Input.GetKeyDown(KeyCode.Space))
{
Dash();
}
}
}
void Dash()
{
dash.Play();
}
Answer by rh_galaxy · Apr 23 at 07:47 PM
Use AudioClip together with an AudioSource, like this:
public AudioClip dash; //set in inspector
AudioSource general;
private void Start()
{
general = GetComponent<AudioSource>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
general.PlayOneShot(dash);
}
}
Your answer
Follow this Question
Related Questions
Add audio clip to a specific audio source 1 Answer
Audio sounds accelerated when starting webplayer??? 1 Answer
Unity and music tracks - load track at certain point and fading tracks in and out 1 Answer
How to achieve lagless sound (no delays)? 2 Answers
sound on button press error + its firing when space is pressed 1 Answer