Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda