unity master volume changer 1

unity master volume changer

public float masterVolume;

Void Start { 



public void AdjustVolume (float newVolume) {
     AudioListener.volume = newVolume;

Here is what the above code is Doing:
1. We create a public float variable called masterVolume.
2. In the Start() function, we call the AdjustVolume() function and pass in the masterVolume variable.
3. In the AdjustVolume() function, we set the AudioListener.volume to the newVolume variable.

Now, we can go back to the Unity Editor and set the masterVolume variable to 0.5f.


Now, when we run the game, the volume will be set to 0.5f.


## Creating a Music Manager

Now, we’re going to create a Music Manager.

First, we’re going to create a new C# script called MusicManager.

Then, we’re going to add the following code to the MusicManager script:

Similar Posts