- Home /
Question by
mossbeard1 · Sep 26, 2018 at 02:52 AM ·
c#soundloopfmodimprovement
I hate the way i looped through these voice lines. Can any of you find an alternative?
public Transform Robot;
public Transform player;
protected FMOD.Studio.EventInstance RobotVoice;
public string[] voicelines;
int j = 0;
bool playnext = false;
private void Start()
{
//for (int i = 0; i < voicelines.Length; i++)
//{
//}
playnext = true;
}
private void Update()
{
//Debug.Log(j);
if(j < voicelines.Length && playnext)
{
RobotVoice = FMODUnity.RuntimeManager.CreateInstance(voicelines[j]);
RobotVoice.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(Robot.position));
StartCoroutine(LateStart(4, voicelines[j]));
}
}
IEnumerator LateStart(float waitTime, string voicepath)
{
playnext = false;
float Timer = 0;
RobotVoice = FMODUnity.RuntimeManager.CreateInstance(voicelines[j]);
RobotVoice.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(Robot.position));
RobotVoice.start();
while (Timer < waitTime)
{
Timer += Time.deltaTime;
FMODUnity.RuntimeManager.SetListenerLocation(player);
yield return 0;
}
yield return 0;
RobotVoice.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
RobotVoice.release();
Timer = 0;
j++;
playnext = true;
}
Comment