Audio.volume

Hello,

I’ve got a sound that is linked to an object that rotates, one that also makes sound.

What the code does is, once the object reached 100% of it’s speed, the volume got to max; 1.
What I want to do is, when the object reaches around 80% of it’s maximum speed, the volume should decrease from that point.

I’ve got no idea on how to do it! Anyone that does have an idea? :slight_smile:

    if (Input.GetKey ("q")  (fanspeed < 50)) {
	   audio.volume = fanspeed * 0.022;
    }

	
    if (Input.GetKey ("q")  (fanspeed > 50)) {
	   audio.volume = fanspeed * -0.022; //This obviously does not work, anyone that can get it done?
    }

    fanspeed = Mathf.Clamp(fanspeed, 0.0, 80);

Thanks in advance!

I think the following will work, although it isn’t very nice code.

if (Input.GetKey ("q")  (fanspeed > 50)) {
  audio.volume = (100 - fanspeed) * 0.022;

HTH

Works, thanks Rooch84!