I have a script that plays an audio file. I want it to play the same sound 10 times with a 3 second period between them (the audio is 2 seconds long).
But I cant get the Ienumerator to work at all.
using UnityEngine;
using System.Collections;
public class RobotTalks : MonoBehaviour
{
public AudioClip Help1;
public void talk(bool n)
{
for(int i=0; i<10; i++)
{
Debug.Log("now i speak"+n + " "+i);
audio.PlayOneShot(Help1);
StartCoroutine(WaitASec(5.0F)); // Problem is here
audio.PlayOneShot(Help1);
}
}
IEnumerator WaitASec(float waitTime){
yield return new WaitForSeconds(waitTime);
}
}
the function talk is trigererd with .sendmessage from another script.
I now it works cause is the debug.log “now i speakTrue 0” … “now i speakTrue 9”
only thing is it happens instantly and i gont get 5 sec delay between debug messages and i only hear the sound once which is probably played instantly 10 times.
any ideas?
(Edit by Berenger : formattage and left only relevant code. Full code)