- Home /
Question by
Doozku · Jul 03, 2015 at 10:17 PM ·
javascriptaudiosourceslidervolume
Volume Slider
I created a slider that is supposed to edit volume. How can I make it so the volume changes with the slider. I tried some things and it didn't work. I keep getting a null reference exception that the object reference is not set to an instance of an object.
Here is one of the functions.
function Update ()
{
if (!GameObject.FindGameObjectWithTag("MM") && CreateMusic == true) {
var musicManager = Instantiate (musicPrefab, transform.position, Quaternion.identity);
musicManager.name = musicPrefab.name;
if(musicManager.GetComponent.<AudioSource>().enabled == false) {
musicManager.GetComponent.<AudioSource>().enabled = true;
}
musicMenu = musicManager;
}
musicManager.GetComponent.<AudioSource>().volume = MainMenu.Volume;
}
another function that does the same thing but for a different level.
function Update ()
{
if (!GameObject.FindGameObjectWithTag("MM") && CreateMusic == true) {
var mManager = Instantiate (musicPrefab, transform.position, Quaternion.identity);
mManager.name = musicPrefab.name;
if(mManager.GetComponent.<AudioSource>().enabled == false) {
mManager.GetComponent.<AudioSource>().enabled = true;
}
MusicManager = mManager;
}
mManager.GetComponent.<AudioSource>().volume = MainMenu.Volume;
}
Here is the script that handles volume.
function SetGameVolume (vol : float) {
Volume = vol;
}
What is supposed to happen is that the Volume var is set to the volume of the audio sources. But it is not working. I want the volume bar to work in multiple levels. How can I do this?
Comment