Help with the code, please. I tried to write the code with which you can add any number of sounds that will be played at a specified interval, in turn. But the problem is that he somehow crookedly works. That is played before, it repeats the same sound several times after passage of time, there is no queue, and so on. I think problem is that "int i" in the cycle is constantly being updated, so there is no priority. But after inscribing check and lowering "int i", sound at all stopped playing. Help me. Thanks In Advance.
using UnityEngine;
using System.Collections;
public class OneShot : MonoBehaviour {
public AudioClip[] Sounds;
public float Timer;
private float TimerDown;
void Start ()
{
TimerDown = Timer;
audio.clip = Sounds[0];
audio.Play();
}
void Update ()
{
int i;
for(i = 1;i < Sounds.Length;i++)
{
if(TimerDown > 0) TimerDown -= Time.deltaTime;
if(TimerDown < 0) TimerDown = 0;
if(TimerDown == 0)
{
TimerDown = Timer;
audio.clip = Sounds[i];
audio.Play();
}
else
{
i=i-1;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire