Answer the question
In order to leave comments, you need to log in
How to modify the script so that the sound level is the same on all scenes?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class settingsmenu : MonoBehaviour {
public AudioSource Music;
public Slider bar;
public void Start()
{
Music.Play();
}
public void Update()
{
AudioListener.volume = bar.value;
}
}
Answer the question
In order to leave comments, you need to log in
Nevertheless, let's give separate advice, I will give a separate answer.
You now have sound settings strongly associated with the playback component itself.
For good, you have a static or global (or whatever you want) data structure for settings.
Alya some class where there is "volume", "additional effects", "selected skin" and so on. just data.
The settings menu will allow these data to be changed and saved.
And here's the playback script - access this data and use it.
for example, if you name a class with GlobalSettings settings))
public class GlobalSettings
{
public static float musicVolume;
}
public void Update()
{
AudioListener.volume = GlobalSettings.musicVolume;
}
float newVolume = //тут как нибудь получаете новое значение
// к примеру из эвента ChangeValue() в слайдере..или еще как
GlobalSettings.musicVolume = newVolume ;
Pass volume between scenes with PlayerPrefs.SetFloat/PlayerPrefs.GetFloat.
Read the Audio Mixer manual and change the volume not with AudioListener.volume , but with AudioMixer.SetFloat .
Was it the same in all scenes? Isn't it easier to indicate that the sound level at the start of the program was equal to the level that you write? (I propose this idea)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question