Hello everyone,
I am new to Unity and I hope you can help me with my problem. My project requires that sounds are played after another. To achieve this, it seems necessary to access the length of the first sound file to create a delay for the second one. However, I created a script to implent an AudioManager an now dont know how to access these information.
I think was I need is a way to receive the AudioSource from the AudioManager.
My code looks as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Windows.Speech;
using System.Linq;
public class VoiceMovement : MonoBehaviour
{
public Animator anim;
public AudioManager theAudio;
public KeywordRecognizer keywordRecognizer;
public Dictionary<string, System.Action> actions = new Dictionary<string, System.Action>();
public void Start()
{
actions.Add("start", start);
anim = GetComponent<Animator>();
theAudio = GameObject.Find("AudioManager").GetComponent<AudioManager>();
keywordRecognizer = new KeywordRecognizer(actions.Keys.ToArray());
keywordRecognizer.OnPhraseRecognized += KeyWordRecognizerOnPhraseRecognized;
keywordRecognizer.Start();
}
public void KeyWordRecognizerOnPhraseRecognized(PhraseRecognizedEventArgs speech)
{
Debug.Log(speech.text);
actions[speech.text].Invoke();
}
public void start()
{
anim.Play("intro");
theAudio.Play("intro_audio");
// HERE I WANT TO ADD THE DELAY
yield return new WaitForSeconds(HERE!!!);
// HERE I WANT TO PLAY THE SECOND SOUND
theAudio.Play("start_audio");
}
Thanks!