How to connect audio clip's with dialog?
Hi,
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.
any solutions?
Thanks
Answer by dimic4 · Apr 24, 2020 at 08:27 AM
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?
Your answer
![](https://koobas.hobune.stream/wayback/20220612232315im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Colliders Stop working when using Game manager 0 Answers
stopping the game and show an animation to user for the points 1 Answer
How to create a 2D slot game in unity step wise step as same as in jetpack joyride? -2 Answers
Admob Work Only In empty project But Not in My Game...!! 0 Answers
Android double jump 0 Answers