Hi, I'm trying to make a simple kids counting game which displays each number (1-100) with the corresponding audio. In my script, I made public Audio Source variables and in the Inspector I linked the Audio Source objects which contain the correct audio files.
Here's the problem: Right now both of my sounds play at the same time. So user will hear audio for 1 and 2 simultaneously. Instead I want the sounds to play one after another while the corresponding number is displayed on screen.
I'm new to Unity and your help is appreciated! Thank you
![alt text][1]
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class GameController_Count : MonoBehaviour {
public Text textNumber;
public Text textNumberAsWords;
public AudioSource a1;
public AudioSource a2;
IEnumerator CountUp () {
for (int textNum = 1; textNum < 100; textNum++) {
print (textNum);
textNumber.text = textNum.ToString ();
if (textNum == 1) {
textNumberAsWords.text = "one";
a1.Play ();
yield return new WaitForSeconds (2.0f);
}
if (textNum == 2) {
textNumberAsWords.text = "two";
a2.Play ();
yield return new WaitForSeconds (2.0f);
}
}
}
void Start () {
CountUp ();
}
[1]: /storage/temp/75695-screen-shot-2016-08-08-at-112112-am.png
↧