Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
No Continue Button is displayed even after the Dialogue is done in Unity

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.

enter image description here

enter image description here

enter image description here enter image description here

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You are prepending a space when you say textDisplaySE.text = " "; and then you add things in the coroutine therefore if(textDisplaySE.text == sentencesSE[index]) is never true because your in the second case textDisplaySE.text is actually [space]test2 instead of just test2 which is what sentencesSE[index].

On line 31 instead you can initialize to textDisplaySE.text = string.Empty; to not have any whitespace.

over 4 years ago · Santiago Trujillo Report

0

In addition to the explanation of your issue from this answer

Why do you need the check at all?

You could simply let your Coroutine handle the end of the typing and enabling the continue button like e.g.

IEnumerator Type()
{
    foreach (char letter in sentencesSE[index].ToCharArray())
    {
        textDisplaySE.text += letter;
        yield return new WaitForSeconds(typingSpeedSE);
    }

    if (index < sentencesSE.Length - 1)
    {
        continueButtonSE.SetActive(true);
    }
}

public void NextSentenceSE()
{
    continueButtonSE.SetActive(false);

    if (index < sentencesSE.Length - 1)
    {
        index++;
        textDisplaySE.text = "";
        StartCoroutine(Type());
    }
    else
    {
        textDisplaySE.text = "";
        Debug.Log("Reached end of dialog");
    }
}

This way you don't need the Update method and string compare at all and wouldn't even get into the issue with the prepend space character ;)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!