Play thruster sound?

Hi, I’m trying to get my spaceships thrusters to have a thruster sound play when a certain key is held down.

This script works but it plays the sound “thrust” over and over when I hold down the key:

void Update () {
       
        if(Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
        {
            audioSource.enabled = true;
            thisParticleRenderer.enabled = true;
            audio.PlayOneShot(thrust);

I know its because its under void update (although I thought PlayOneShot meant play once) but how do I get the sound to play when “S” or “D” is held down and loop but not play over itself on over and over? I hope that made sense :slight_smile: any help is greatly appreciated.

easy way: (start playing the loop only if its not already playing)

if (!audio.isPlaying) audio.Play();

could be nicer if volume gets adjusted when starting to play and the fade out when key is released…

1 Like

Hey gear, thanks for pointing me in the right direction, this is what worked in my case:

if (!audio.isPlaying) {
                audio.clip = thrust;
                audio.Play ();
            }

I’m not sure how to make the sound fade in and out upon key touch but it sounds awesome. will look into it.