- Home /
Get TextMeshProUGUI text to display series of strings in seperate array? Dialogue System.
Right now I have a simple trigger enter and exit script in which if the player enters an area in front of an NPC, a text GUI object will appear on screen, representing the NPC's dialogue.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class DialogueInteraction : MonoBehaviour
{
public Dialogue dialogue;
public TextMeshProUGUI dialogueText;
private bool triggerEntered = false;
void Update()
{
if (Input.GetButtonDown("Interact") && triggerEntered == true)
{
dialogueText.enabled = true;
}
else if (triggerEntered == false)
{
dialogueText.enabled = false;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
triggerEntered = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
triggerEntered = false;
}
}
}
I have a reference to a separate script called Dialogue, which contains parameters for what would be the dialogue itself in a series of strings:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue {
[TextArea(3, 10)]
public string[] sentences;
}
My Question is how I can get my Text in the first script to display the series of strings as they are determined in the editor? The DialogueInteraction script would be attached to the NPC, and I want it so that if the player presses the interaction button, the text object will appear and display the series of strings in the Dialogue script in order, one at a time. I've searched lots of places online but there seems to be a serious lack of information on dialogue systems that aren't pre-made assets.
Your answer
![](https://koobas.hobune.stream/wayback/20220612191704im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trying to make an ASCII UI based game 0 Answers
Can't destroy an arrray with GUI Text 1 Answer
GUI Label Width & Height 0 Answers
GUIText Problem With MENU 1 Answer
Gui Button Solid 2 Answers