I can’t figure out this audio problem. My code works the first time around, but every time I try to play the sound again, nothing comes out of the speakers. I put debug code around the audiosource.Play() line, and it claims that it’s playing the sound at the right time. What am I doing wrong?
I have an empty called Audi:eyes:bject.
Audi:eyes:bject has an Audio Source attached to it.
Audio Clip: X.wav
Play on awake: box not checked
Volume 1
Pitch 1
Min Volume 1
Max Volume 1
Rollof Factor 0
Loop: box not checked
I have this code in a c# script. This script is not attached to any object and isn’t derived from MonoBehavior.
Xsound = (AudioSource) GameObject.Find("Audi:eyes:bject").GetComponent(typeof (AudioSource));
.
.
.
if (Xsound==null) Debug.Log ("Xsound is null");
if (Xsound.isPlaying) Xsound.Stop();
Debug.Log ("Is sound Playing? " + Xsound.isPlaying);
Xsound.Play();
Debug.Log ("Is sound Playing? " + Xsound.isPlaying);
and I get this output in the debug log:
Is sound Playing? False
Is sound Playing? True
It works the first time through, but then it never works again until I exit unity and get back in.