我是C#和Unity的新手,我尝试实现了一个音量滑块。我现在可以调整音量,但每次尝试加载新场景时音量都会重置。
有人能告诉我如何将音量转移到其他场景吗?我使用的是Unity 2018.3.14f1,我使用的卷代码是:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class SetVolume : MonoBehaviour
{
public AudioMixer mixer;
public void SetLevel(float sliderValue)
{
mixer.SetFloat("MusicVol", Mathf.Log10(sliderValue) * 20);
}
}发布于 2021-02-01 00:45:59
将其保存在PlayerPrefs中,然后在Start或需要的任何位置加载它。
public class SetVolume : MonoBehaviour
{
public AudioMixer mixer;
void Start()
{
SetLevel(PlayerPrefs.GetFloat("MusicVol"));
}
public void SetLevel(float sliderValue)
{
PlayerPrefs.SetFloat("MusicVol", sliderValue);
mixer.SetFloat("MusicVol", Mathf.Log10(sliderValue) * 20);
}
}https://stackoverflow.com/questions/65980381
复制相似问题