Hi, I would like to play a sound when the player enter the collider and then after 10 sec only the second coroutine will call. but unfortunately it seems that coroutine is running at the same time(there is no delay). below is the code. Hope somebody can help me. PLEASE…
void OnTriggerEnter( Collider col)
{ if (col.gameObject.tag == “Player” )
{
StartCoroutine("AudioStart");
StartCoroutine("WaitHere");
} // end if
//FPCStart.ansq++;
//Debug.Log (GameControl.control.ansq++);
}//end function on trigger enter
IEnumerator AudioStart()
{
audio.clip = StartAns;
audio.Play ();
yield return new WaitForSeconds (10.0f);
}// end function AudioStart
IEnumerator WaitHere()
{ float timeLeft = 0.0f;
while (timeLeft<10.0f && !Ans)
{
timeLeft += Time.deltaTime;
Fig.SetActive (true);
if (Input.GetKeyDown(KeyCode.Y))
{
GameControl.control.correctAns +=1;
GameControl.control.Correct();
Ans = true;
}
else if (Input.GetKeyDown(KeyCode.T))
{
GameControl.control.wrongAns +=1;
Ans =true;
}
yield return null;
}// end while
Destroy (Fig);
if (Ans == false)
{
audio.clip = endGame;
audio.Play ();
}
}// end ienu
but in the first coroutine i already wait for 10.0f.
– Malbari1Thank you Technique,now I understand what u meant just now. i really appreciate it.
– Malbari1Glad to help, Coroutines are a bit tricky at first, but a great tool once you understand them. If it's all ok, can you please mark one of the answers so the question can be closed?
– Tehniqueok. I'm sorry for the confusion. Thank you Tehnique.
– Malbari1