Y
Y
yraiv2022-03-17 06:55:33
Unity
yraiv, 2022-03-17 06:55:33

How to adjust the volume using the slider?

I am adjusting the volume of music and effects, I found several video examples, I repeat as there, but the result is different.

public AudioMixerGroup Mixer;

 public void ChangeVolumeMusic(float volume)
    {
        Mixer.audioMixer.SetFloat("MusicVolume", Mathf.Lerp(-80, 0, volume));
    }


I stuck the method to the slider, but when I start to change the slider even a little, the sound stops immediately, but it works fine on the video, what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
K0TlK, 2022-03-17
@yraiv

You should at least look at the documentation for what Mathf.Lerp is before blindly blindly copy-pasting the code from the video: https://docs.unity3d.com/en/2019.4/ScriptReference... . You absolutely do not need lerp here, because if you set t less than one, then when you try to set the volume to 100 (or another number), you will have it less than 100. And if t is equal to 1, then there is no point in linear interpolation. replace with just volume. Mathf.Lerp(-80, 0, volume)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question