I have a GameObject with an AudioSource attached and in a script on the same object I’m calling the following simple code:
void PlayAudio()
{
audio.enabled = true;
if (!audio.isPlaying)
{
audio.Play();
}
}
Oddly I get the warning Can not play a disabled audio source
and audio does not play. I’ve stepped through the code and audio is very clearly enabled.
I have noticed however that audio does play if I select “Play On Awake” in the Audio Source settings, though when the audio plays I still get the same Can not play a disabled audio source
warning.
There’s a few questions about this error on this site, but most are due to someone destroying objects holding Audio Sources. This is not the case in my scene and no GameObjects are being destroyed anywhere.
Is there anything special I need to do to setup a Audio Source that I may not be doing? Why would audio only play if I’ve selected “Play on Awake?”