Dialog issue
I Have a problem with a dialog script I have been working on when you press the continue button in the User interface it doesn't display the next sentence however there isn't any errors
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Dialog : MonoBehaviour {
public GameObject DialogUI;
private Gamemaster gm;
public TextMeshProUGUI testDisplay;
public string[] sentences;
public float typingSpeed = 0.02f;
private int index;
void OnTriggerEnter(Collider col)
{
if (col.CompareTag("Player"))
{
gm.HelpText.text = ("Press [E] To Talk");
if (Input.GetKey("e"))
{
Time.timeScale = 0f;
gm.HelpText.text = (" ");
DialogUI.SetActive(true);
}
}
}
void OnTriggerStay(Collider col)
{
if (col.CompareTag("Player"))
{
gm.HelpText.text = ("Press [E] To Talk");
if (Input.GetKey("e"))
{
gm.HelpText.text = (" ");
DialogUI.SetActive(true);
}
}
}
void Start()
{
gm = GameObject.FindGameObjectWithTag("GameMaster").GetComponent<Gamemaster>();
StartCoroutine(Type());
}
IEnumerator Type()
{
foreach(char letter in sentences[index].ToCharArray())
{
testDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void NextSentence()
{
if(index < sentences.Length -1){
index++;
testDisplay.text = "";
StopCoroutine(Type());
} else {
testDisplay.text = "";
}
}
public void ExitDialog()
{
Time.timeScale = 1f;
DialogUI.SetActive(false);
}
}
capture.png
(47.2 kB)
Comment