- Home /
fade in fade out audio manager
this is my audio manager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : MonoBehaviour
{
public AudioSource BGM;
public float musicTimer;
void Start()
{
musicTimer = 0f;
DontDestroyOnLoad(gameObject);
if(FindObjectsOfType<AudioManager>().Length >1)
{
Destroy(gameObject);
}
}
// Update is called once per frame
void Update()
{
musicTimer = BGM.time;
}
public float getTime()
{
return musicTimer;
}
public void ChangeBGM(AudioClip music)
{
if (BGM.clip.name == music.name)
return;
BGM.Stop();
BGM.clip = music;
BGM.Play();
;
}
}
**and i am having trouble of creating fade in fade out.. this is my switch on load code:**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SwtichMusicOnLoad : MonoBehaviour
{
public AudioClip newTrack;
private AudioManager theAM;
private float wait;
private float now;
private float waitingtime;
void Start()
{
theAM = FindObjectOfType<AudioManager>();
wait = theAM.GetComponent<AudioSource>().clip.length;
now = (theAM.getTime());
waitingtime = wait - now;
if (newTrack != null)
{
Debug.Log("changing song");
theAM.ChangeBGM(newTrack);
}
}
I used a turiol on youtube, and now i am lost, and tired :( for the dont destroy on load i have a script that deletes the old one.. so.. I dont know how to fade in fade out now.. I want to fade in fade out every time a level ends.. means a new track.. but when i tried various functions it faded every time the level resets and didnt fade on level transition.. kind of lost and need help a guidance. i know i will have many moments like this LOL but i am hoping for some good advice.. thanks in advance for you paitince
Comment