I have an audio source that’s assigned in my script. In the update function, I have the following code:
if (CoverTimer < 0.5f && SndCoverMove != null && !SndCoverMove.isPlaying)
{
SndCoverMove.Play();
Debug.Log("Play cover sound");
}
When I run the game, the sound does not play, and the log shows about thirty instances of “Play cover sound”, one frame after another. So, even though Play() is getting called, isPlaying never gets set to true.
I’ve tried setting the sound to “Play on Awake” and it plays fine then, but not when called from code, so the actual AudioSource is set up correctly, and so is the clip that’s assigned to it. I’ve tried setting the audio source’s priority to 1, with no effect.
This is driving me crazy… I’ve been using Unity for a long time now, but I’ve never seen the audio source silently fail like this before. Does anyone know of any arcane conditions that I may be missing to get this to work?
Edit: Found the problem. When the audio source was created, it was duplicated from another audio source. Another script, for whatever reason, decided to keep a reference to the duplicate rather than the original, so that completely unrelated script was preventing it from playing. Thanks for the help and sorry for wasting your time.