I have a GameObject with an Audio Source and the script below. This object only exists in the first level of my game. When the game starts the music starts playing. The problem I have is that each time I load a new level the sound gets louder. I don’t understand why this is happening. Can someone explain why this is happening and give a possible solution?
using UnityEngine;
using System.Collections;
public class MusicManagerScript : MonoBehaviour
{
public AudioClip[] songs;
int currentSong = 0;
// Use this for initialization
void Start() {
DontDestroyOnLoad(gameObject);
}
// Update is called once per frame
void Update() {
if (audio.isPlaying == false) {
currentSong = currentSong % songs.Length;
audio.clip = songs[currentSong];
audio.Play();
currentSong++;
}
}
}