Side thruster sounds, possible solution

I took the solution from this yt video, basically you need a second audio source in the game object, as there is one already being used for the main engine. So the Stop method shuts it off, and then if you want to start it/shut it off while you’re rotating, it becomes a complete mess.

[SerializeField] AudioClip mainEngine;
[SerializeField] AudioClip sideEngine; // add a separate variable for the side engine clip
AudioSource engineSFX;
AudioSource sideEngineSFX; // separate variable for second audio source
void Start()
    {
        rb = GetComponent<Rigidbody>();
        engineSFX = GetComponent<AudioSource>();
        sideEngineSFX = gameObject.AddComponent<AudioSource>(); 
     // on game start add a second audio source to the game object, which the script is attached to
    }
ApplyRotation(rotationValue);
        if (!leftThruster.isPlaying)
        {
            leftThruster.Play();
        }
        if (!sideEngineSFX.isPlaying)
        {
            sideEngineSFX.PlayOneShot(sideEngine); //use the 2nd source with side engine clip
        }
private void StopRotationEffects()
    {
        rightThruster.Stop();
        leftThruster.Stop();
        sideEngineSFX.Stop(); // stop the sound playback on the 2nd source
    }

If you keep holding one of the turn keys on crash/succeed, the audio from the second source still keeps playing, I’ve just found out. So I’m back to square one, as to solve this I’d need a way to target the second audio source on the game object in the script. Moving on for now.

You’ll get there.

There’s lot of opportunities for data checking when doing stuff like this. Noticing an issue and finding a solution that works and hope like hell it didn’t create another issue. A good session of wack-a-mole.

1 Like

You could add an AudioSource to each of the side engines, then create two SerializedField variables to hold those two side engines. If you do this from within the edit prefab mode, then you can drag each engine into the field with its name. Then in your code you can turn the sounds of all three thrusters on and off with ease and without overlap.

A better, though more complex approach is to use an AudioMixer component, which is a convenient way to combine controlling multiple audio sources on one object.

Good for you for going the extra distance! :grinning::+1:

Privacy & Terms