I don't want the player to spam the continueButtonSE hence, I only want it to appear after the dialogue has finished.
It works in the first index but for the next element, the continueButton does not appear. Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class DialogueSE : MonoBehaviour
{
public TextMeshProUGUI textDisplaySE;
public string[] sentencesSE;
private int index;
public float typingSpeedSE;
public GameObject continueButtonSE;
void Start()
{
StartCoroutine(Type());
}
void Update()
{
if(textDisplaySE.text == sentencesSE[index])
{
continueButtonSE.SetActive(true);
}
}
IEnumerator Type()
{
foreach (char letter in sentencesSE[index].ToCharArray())
{
textDisplaySE.text += letter;
yield return new WaitForSeconds(typingSpeedSE);
}
}
public void NextSentenceSE()
{
continueButtonSE.SetActive(false);
if (index < sentencesSE.Length - 1)
{
index++;
textDisplaySE.text = " ";
StartCoroutine(Type());
}
else
{
textDisplaySE.text = " ";
continueButtonSE.SetActive(false);
}
}
}
I've disabled the continueButtonSE from the start so that it can only appear once sentencesSE[index] is done appearing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…