Audio doesn´t mute when i use my slider
Hi, first of all, I´m new in all of this , I don´t even know how to program i mean i wwill study but right now i´m not in university but i wanted to start a little game so i was making my little game but i have a problem. When i use my slider the audio doesn´t change, the script in the slider is fine because the AudioMixer in fact change but it doesn´t affects to the audio, i think that it could be a problem with the audio because the audio has a script to not DestroyOnLoad because it was the only way that i figure to stop the restart of the audio everytime that my player dies (every time that dies the scene restarts buut also the music and i want that the music continues even if the player die) so i don´t know what to do, i guess is because the audio is ina script DontDestroyOnLoad but i´m not too sure.
This the Script from the Audio Slider Buton
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Audio;
public class SettingsVolume : MonoBehaviour { public AudioMixer audioMixer;
public void SetVolume(float volume)
{
audioMixer.SetFloat("Volume", volume);
}
}
And this is the two scripts for the audio, one is for play randoms clips (It has more than one song) and the other one is to not restart the music every time that my player dies
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DontDestroy : MonoBehaviour {
1.-First One
void Awake ()
{
GameObject[] objs = GameObject.FindGameObjectsWithTag("Music");
if (objs.Length > 1)
Destroy(this.gameObject);
DontDestroyOnLoad(this.gameObject);
}
}
2.-RandomSountracks
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class RandomSoundtrack : MonoBehaviour {
public AudioClip[] clips;
public AudioSource Source;
public float newClip;
public float timer;
// Use this for initialization
void Start () {
Source = gameObject.AddComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
timer += Time.deltaTime;
if(timer >= newClip)
{
newCLIP();
timer = 0;
}
}
void newCLIP()
{
int clipNum = Random.Range(0, clips.Length);
if (!Source.isPlaying)
{
Source.loop = true;
Source.PlayOneShot(clips[clipNum]);
}
newClip = clips[clipNum].length;
{
}
}
}
ps: Sorry for any grammar mistakes, I´m mexican so english is not my native language.