You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
892 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class AudioManager : MonoBehaviour {
public static AudioManager Instance {
get; set;
}
private void Awake() {
//Manage Singleton
if (Instance != null && Instance != this)
Destroy(gameObject);
else
Instance = this;
DontDestroyOnLoad(gameObject);
}
public AudioMixer audioMixer;
public AudioClip[] sceneMusic;
//Value range is 0 - 1, we map it into -80 - 0
public void SetMusicsVolume(float value) {
float db = value * 80 - 80;
audioMixer.SetFloat("musicVol", db);
}
//Value range is 0 - 1, we map it into -80 - 0
public void SetSFXVolume(float value) {
float db = value * 80 - 80;
audioMixer.SetFloat("sfxVol", db);
}
public void FadeMusicForScene(int index) {
GetComponent<FadingAudioSource>().Fade(sceneMusic[index], 1, true);
}
}