Hi, Haven’t worked in Unity in a long time and found this small problem that i cant get my head around.
Im simply trying to play a sequence of drum kicks while making an object flash to the beat.
The problem i am having is simply getting the audio to take a break between sounds to i can make a proper rhythm.
it just ignores my yield calls and loops the playlist at its own pace.
public var sound:AudioClip[];
private var count:int=0;
private var originalMaterial:Material;
public var beatMaterial:Material;
function Start () {
originalMaterial=GetComponent(MeshRenderer).material;
}
function Update () {
if(count==sound.Length){
count=0;
}
if(!audio.isPlaying){
playBeat(count);
renderer.material=originalMaterial;
count++;
}else if (audio.isPlaying){
renderer.material=beatMaterial;
}
}
function playBeat(i:int){
audio.clip=sound*;*
audio.Play();
switch(i) {
case 0:
yield WaitForSeconds(2);
break;
case 1:
yield WaitForSeconds(1);
break;
case 2:
yield WaitForSeconds(30);
break;
case 3:
yield WaitForSeconds(1);
break;
case 4:
yield WaitForSeconds(1);
break;
case 5:
yield WaitForSeconds(2);
break;
case 6:
yield WaitForSeconds(1);
break;
}
Debug.Log(i+“beat”);
}