I have this volume slider that can only be accessed in the menu and it has a saving function that save the volume when you leave but the save volume is only loaded when you load the menu not on starting the game. I can’t get it to load on start so can someone please help me
here’s the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SoundManager : MonoBehaviour
{
[SerializeField] Slider volumeSlider;
// Start is called before the first frame update
void Start()
{
if (!PlayerPrefs.HasKey("musicVolume"))
{
PlayerPrefs.SetFloat("musicVolume", 1);
}
else
{
Load();
}
}
public void ChangeVolume()
{
AudioListener.volume = volumeSlider.value;
Save();
}
public void Load()
{
volumeSlider.value = PlayerPrefs.GetFloat("musicVolume");
}
public void Save()
{
PlayerPrefs.SetFloat("musicVolume", volumeSlider.value);
}
}