Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Play a variety of audio source objects from a for loop

$
0
0
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

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>