I try to build my first, simple singleton soundmanager, which hold reference for all sound effects trough some scenes. I have a SoundManager object with two Audio Sources for background music and mouse click sound. In the SoundManager script I have a function (buttonTrigger) which plays the sound, when the button is clicked. I added this function to the UI button On Click() settings.
Problem: when I try to click I get this message: cannot play a disabled audiosource.
But this isn’t disabled, I don’t know what is the problem.
Any idea?
Thanks
using UnityEngine;
using System.Collections;
public class SoundManager : MonoBehaviour {
public static SoundManager Instance;
public AudioSource menuMusic;
public AudioSource clickSound;
void Awake()
{
// there is one single public static instance of one class
if (Instance == null)
{
DontDestroyOnLoad(gameObject);
Instance = this;
}
else if (Instance != this)
{
Destroy(gameObject);
}
}
// Use this for initialization
void Start () {
StartMenuMusic();
}
public void StartMenuMusic()
{
menuMusic.loop = true;
menuMusic.Play();
}
public void buttonTrigger()
{
clickSound.Play();
}
}