I wrote a script to lower the volume music and then load a scene but I get an UnassignedReferenceException (The Audio Source is on another Game Object).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class StartGame : MonoBehaviour {
public AudioSource music;
bool loadGame = false;
public void Update(){
if (loadGame)
music.volume = Mathf.Lerp (music.volume, 0, Time.deltaTime * 3);
if (music.volume <= 0.01f)
SceneManager.LoadScene (1);
}
public void LoadGame(){
loadGame = true;
}
}
Am I doing something wrong? The script works exactly as intended.