- Home /
Question by
Squammy_U · Nov 21, 2017 at 06:36 PM ·
c#textaudiosourcecoroutines
Audio Not Lining Up With Text
So I found an old unity script from someone on the internet and edited it to be used with the latest version of Unity. It works fine except the sound effect that plays for each character if delayed about a half a second after the letter prints on the screen. Am I missing something? Thanks.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class type : MonoBehaviour
{
public float letterPause = 0.2f;
public AudioClip sound;
string message;
void Start()
{
message = GetComponent<Text>().text;
GetComponent<Text>().text = "";
StartCoroutine(TypeText());
}
IEnumerator TypeText()
{
foreach (char letter in message.ToCharArray())
{
GetComponent<Text>().text += letter;
GetComponent<AudioSource>().PlayOneShot(sound);
yield return 0;
yield return new WaitForSeconds(letterPause);
}
}
}
Comment
Well i just runned your Script. With a SoundEffect, and it worked perfect.
you might want to check if your AudioClip really begins at Beginning, or if it has any Delay. Then you want to cut this out with an Audio Software.
Your answer
![](https://koobas.hobune.stream/wayback/20220612143119im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Convert Audio Beeps And Dashes into Text 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Coroutines white death causes? 0 Answers
How to play "audiosource" component in a prefab from script? 0 Answers