hi, I’m working in a game whereby an audio will be played when the player is loss.unfortunately is not working. below is the code. when i debug by writing the audio instruction in the “Start” function is working which there is no problem with the audio. where did i do wrong ? Please help me to solve this problem
void Update()
{
if (GameControl.control.ansq == 2)
{
if (GameControl.control.correctAns <4)
{
audio.clip = endGame;
audio.Play();
StartCoroutine("GameOver");
}
else
LevelTwo();
}// end if level 1
}// end function Update
IEnumerator GameOver()
{
yield return new WaitForSeconds (3.0f);
imageTex.enabled = true;
imageTex.texture = lossImage[0];
}// end function GameOver
I think the problem is here: " if (GameControl.control.correctAns <4) "
I believe that you start the audiosource in the update function without checking if it is already playing so with each frame it stops the audio and starts it all over again.
It works in the start function because the start function is called only once while update is called all the time.
try changing the condition so that it takes into consideration if the source is playing or not.
Do you have an audio listener within the world?
If it’s a 3D sound, is it close enough?
Is the volume alright?
Do you have an audioSource?
Do you have the soundclip in a variable?
Do you assign said soundclip to a source?