- Home /
Question by
lauritsbrok · Apr 18, 2018 at 09:18 AM ·
2d2d gamesound effects
Overlay Sound Effect When Space Bar Is Pressed
I have a code that plays a sound every time the player presses space. However, the sound stop and plays a new again if you press the space button twice. I want the sound to be able to overlay each other if the space button is pressed twice.
This is my code:
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
MusicSource.Play();
}
Thanks!
Comment
Try the static AudioSource.PlayClipAtPoint() function, which instantiates a new AudioSource and automatically disposes of it when the sound stopped playing.
Answer by finlay_morrison · Apr 18, 2018 at 12:49 PM
Try using MusicSource.PlayOneShot() , i haven't used PlayOneShot before, but i belive that that will produce the effect that you want