Hello everyone.
I’m getting crazy about the volume thing. I wrote the code myself and it didn’t work then I follow the lecture and it’s true but not working. I can read volume by Debug.Log but cannot set it. Here are my codes for music manager and our debugging script.
public class setThingsAtStart : MonoBehaviour {
MusicManager audioSource;
float volSet;
// Use this for initialization
void Awake ()
{
audioSource = gameObject.GetComponent<MusicManager> ();
volSet = PlayerPrefsManager.getMasterVolume ();
Debug.Log ("Master Volume is: " + PlayerPrefsManager.getMasterVolume ());
}
void Start()
{
audioSource.setVolume (volSet);
Debug.Log("Volume Set as: " +volSet);
}
}
Here is music Manager
public class MusicManager : MonoBehaviour {
public AudioClip[] levelMusicChangeArray;
[SerializeField] int levelIndex;
AudioSource audioSource;
void Awake()
{
DontDestroyOnLoad (this);
}
void Start ()
{
audioSource = GetComponent<AudioSource> ();
}
void OnLevelWasLoaded()
{
levelIndex = SceneManager.GetActiveScene ().buildIndex;
AudioClip thisLevelMusic;
thisLevelMusic = levelMusicChangeArray [levelIndex];
if(thisLevelMusic)
{
audioSource.clip = thisLevelMusic;
audioSource.Play ();
if (levelIndex < 0)
{
audioSource.loop = true;
}
}
}
public void setVolume(float volume)
{
audioSource.volume = volume;
}
}