How to allow other audio clips to play but stop thruster audio?

I’m having an issue stopping the thruster audio clip is preventing any audio playing, as in the else condition I can’t specify which clip to stop playing so it’s all audio. So while the space bar is not pressed, audio is constantly being stopped. Therefore any collision noise I have will not play unless I am thrusting.

void ProcessThrust()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            // rocketRigidbody.AddForce(Vector3.up);
            rocketRigidbody.AddRelativeForce(Vector3.up * thrustPower * Time.deltaTime);
            if (!audioSource.isPlaying)
            {
                audioSource.PlayOneShot(thrusterClip);
            }
        }
        else
        {
            // audioSource.Stop();
        }
    }

Commenting out audioSource.Stop() allows bumps to play while not thrusting but then the whole audio clip for the thrust noise plays until finish.
The only way I can think of fixing this is having the collision script on other objects than the rocket, so audio is played from those objects. Or making an audio handler class of some sort.

PlayOneShot plays audio all the way through at a specific (vector3) point in space. It’s not really designed to get interrupted. If you want to be able to interrupt the sound, set the audioSource up with your clip (and other settings if needed) and then run audioSource.Play(); Then audioSource.Stop() will do what you expect it to do.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms