how to play a looping sound only while a float is equal to a certain number

Hello, so I made a float that gets changed when you scroll a mouse wheel. Now I'm trying to make it so when a number is above zero it plays a sound of a booster but when it is below zero it stops playing.
I made this:

void SoundManager()
        {
            if (MovingSpeedRn >=1)
            {
                if (IsPlayingSound = false)
                {
                    Booster.Play();
                    IsPlayingSound = !IsPlayingSound;
                }

            }
            if (MovingSpeedRn ==0)
            {
                if(IsPlayingSound = true)
                {
                    Booster.Stop();
                    IsPlayingSound = !IsPlayingSound;
                }

            }
        }

But It doesn't work, pls hellp me

  1. What doesn't work? Doesn't it play? Doesn't it loop?
  2. It's better to just put the bool to true and false, since you are playing and stopping.
  3. Is soundmanager being called?

also that code doesn't check if its below zero, but mouse scroll speed can be negative.

can be easier to adjust volume, instead of stopping and playing, in 1 line:

Booster.volume = MovingSpeedRn < 1 ? 0 : 1; // if MovingSpeedRn is below 1, set volume to 0, otherwise set to 1
1 Like