Basically I want to save the audio mixer dB numbers once you change it using the slider in the settings page of my game, so when you leave and rejoin the game, the volume will stay the same as to what the the player set the volume to. I've tried quite a few types of code but id didn't work for me. This is the code I have set for my settings script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
public class SettingsScript : MonoBehaviour
{
public AudioMixer audioMixer;
public Slider slider;
public float sliderValue;
public void Start()
{
slider.value = PlayerPrefs.GetFloat("save", sliderValue);
}
public void SetVolume(float volume)
{
audioMixer.SetFloat("volume", volume);
}
public void ChangeSlider(float value)
{
sliderValue = value;
PlayerPrefs.SetFloat("save", sliderValue);
}
}
If you need any other lines of code or names of some sort, feel free to ask!
↧