This dialogue is triggered with a seperate script using OnTriggerEnter2D and Input.GetKeyDown, but when i try to trigger again, nothing happens. The script is on an object which has an UI Text and Sound etc as children.
public class DialogController : MonoBehaviour
{
public Text textDisplay;
public string[] sentences;
private int index;
public float typingSpeed;
public AudioSource audioSource;
public AudioClip typingSound;
private bool isTyping = false;
private bool finished = false;
public void Start()
{
StartCoroutine(Type());
PlayerController.PlayerControlsEnabled = false;
WitchController.WitchControlsEnabled = false;
}
void Update()
{
if(!isTyping && Input.GetKeyDown(KeyCode.E))
{
NextSentence();
}
if(finished == true)
{
index = 0;
this.gameObject.SetActive(false);
}
}
public IEnumerator Type()
{
isTyping = true;
foreach(char letter in sentences[index].ToCharArray())
{
textDisplay.text += letter;
audioSource.PlayOneShot(typingSound);
yield return new WaitForSeconds(typingSpeed);
}
isTyping = false;
}
public void NextSentence()
{
if(index < sentences.Length - 1)
{
index++;
textDisplay.text = "";
StartCoroutine(Type());
}
else
{
finished = true;
textDisplay.text = "";
PlayerController.PlayerControlsEnabled = true;
WitchController.WitchControlsEnabled = true;
}
}