Question by
SimLoadsMedia · Jan 05, 2019 at 08:31 PM ·
c#unity 5audioaudiosource
AudioSource.Play plays every sound at once,AudioSource.Play Plays every source at once
Okay, I'm totally lost. I have a sequence of sounds I want to play in order with small delays between each one. They all play fine, except the delays are totally ignored and all the sounds play at the same time. I should also note that the stop function for 'movementLoop' doesn't actually stop the clip. I'm pretty much brand new to Unity so any explanation or help would be much appreciated :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class elevatorMovement : MonoBehaviour
{
[SerializeField] Animator elevator;
public AudioSource movementLoop, start, stop, startSpeak, stopSpeak;
public void ElvRun()
{
Debug.Log("Movement called");
movementLoop = GetComponent<AudioSource>();
start = GetComponent<AudioSource>();
stop = GetComponent<AudioSource>();
startSpeak = GetComponent<AudioSource>();
stopSpeak = GetComponent<AudioSource>();
StartCoroutine(elevatorScript());
}
IEnumerator elevatorScript()
{
Debug.Log("Coroutine started");
startSpeak.Play();
yield return new WaitForSeconds(2);
start.Play();
elevator.Play("elevatorMovement");
movementLoop.Play();
yield return new WaitForSeconds(5);
stop.Play();
movementLoop.Stop();
yield return new WaitForSeconds(1);
stopSpeak.Play();
}
}
,Okay, I'm totally lost. I have some code that I want to play a sequence of audio files, and it does play them, but instead of waiting the defined amount of time, it just plays them all at once. It also fails to stop movementLoop too.
I don't know what to do, as I'm almost completely new to Unity. Any ideas?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class elevatorMovement : MonoBehaviour
{
[SerializeField] Animator elevator;
public AudioSource movementLoop, start, stop, startSpeak, stopSpeak;
public void ElvRunboi()
{
Debug.Log("Movement called");
movementLoop = GetComponent<AudioSource>();
start = GetComponent<AudioSource>();
stop = GetComponent<AudioSource>();
startSpeak = GetComponent<AudioSource>();
stopSpeak = GetComponent<AudioSource>();
StartCoroutine(elevatorScript());
}
IEnumerator elevatorScript()
{
Debug.Log("Coroutine started");
startSpeak.Play();
yield return new WaitForSeconds(2);
start.Play();
elevator.Play("elevatorMovement");
movementLoop.Play();
yield return new WaitForSeconds(5);
stop.Play();
movementLoop.Stop();
yield return new WaitForSeconds(1);
stopSpeak.Play();
}
}
Comment