- Home /
Cant Get Dialogue Trigger Working
I know it's been asked a lot but I cant find a solution anywhere. Im trying to create a basic dialogue system where the end goal is that I can approach an NPC and start dialogue after either clicking on it or pressing a button. I have the dialogue part and it works fine, but I cant figure out a trigger. Here's my code for the dialogue.
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro;
public class Dialogue : MonoBehaviour{
public TextMeshProUGUI textDisplay;
public string[] sentences; // holds all sentences
private int index; //int variable
public float typingSpeed;
public string name;
public GameObject continueButton;
public Animator animator;
void update (){
if(textDisplay.text == sentences[index]){
continueButton.SetActive(true);
}
}
// Start is called before the first frame update
public void StartDialogue(){
animator.SetBool("IsOpen", true);
StartCoroutine(Type());
}
public IEnumerator Type(){ //coroutine
foreach(char letter in sentences[index].ToCharArray()){
textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
//delays code by typing speed
}
}
public void NextSentence(){
if (index < sentences.Length - 1){ //if we are at the end of dialogue
index++; //increments the characters
textDisplay.text = "";
StartCoroutine(Type());
} else {
textDisplay.text = "";
continueButton.SetActive(false); //disables cont at end of dialogue
animator.SetBool("IsOpen", false);
}
}
}
You can use the event system to trigger the start of the dialogue by pressing a button or clicking (as you said yourself)
Your answer
Follow this Question
Related Questions
Conversation Bubbles and starting it 1 Answer
How to organize NPC dialogs? 0 Answers
Detect a collision point, but allow pass through collider. 0 Answers
Dialogue character emotions system 1 Answer
2D Collision detection not working 0 Answers