so, i’m working on a game, and i have a dialog between two people. I already make, that when the player click on button next, the next dialoge is shown. i have 9 dialogs, so the player must press 9 times on button next, to end up dialoge.
The problem i have now, that i want when text is shown the audio clip(i recorded voices and export as mp3 in audacity) is on volume too. i have 9 audio clips and i can’t pair it with texts.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using TMPro;
public class Dialog : MonoBehaviour
{
// Start is called before the first frame update
public TextMeshProUGUI textDisplay;
public string[] sentences;
private int index;
public float typingSpeed;
public GameObject continueButton;
void Start()
{
StartCoroutine(Type());
}
void Update()
{
if(textDisplay.text == sentences[index])
{
continueButton.SetActive(true);
}
}
IEnumerator Type()
{
foreach(char letter in sentences[index].ToCharArray())
{
textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void NextSentence()
{
continueButton.SetActive(false);
if(index < sentences.Length - 1)
{
index++;
textDisplay.text = "";
StartCoroutine(Type());
} else {
SceneManager.LoadScene("Animation"); ;
}
}
}
So that’s my code, what i must add to the code, so when the text is shown on screen, audio clip is played at same time? and every time i click on button next, the next sentence and audio clip is played?