Hello Hello,
I am attempting to set some TextMeshPro text using a custom list, but there seems to be an error, issue, or bug that is causing it to not work (unless I misunderstand something)
Here’s a screenshot (I’m currently customizing one of the unity learning games)
I have my custom list which takes 3 variables
- string dialogue (what we want to say)
- string speaker (who is saying it)
- color color (the color we want to assign to those texts)
THE ISSUE
I can set the text directly like this in start or update
tmp_Dialogue.text = "hello| "
And I can even get it to work when I do it in start or update
tmp_Dialogue.text = list_DialogueDict[int_DialogueID].dialogue;
But calling the code through my function causes the dialogue to show BLANK even though the inspector shows what I want
Anyways, I’ll dump my script, and any help is appreciated if I’m missing something
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
using TMPro;
/// <summary>
/// <para> UI Text Manager references all of the important UI for buttons, text, and portraits that may show during conversations </para>
/// </summary>
[System.Serializable]
public class UITextManager : MonoBehaviour
{
//dialogue text obj & speaker text obj
[SerializeField] private TextMeshProUGUI tmp_Dialogue, tmp_Speaker;
//dictionary list of conversational elements to add
[SerializeField] public List<DialogueDictionary> list_DialogueDict = new List<DialogueDictionary>();
// the dialogue ID we're on
private int int_DialogueID;
private string _testString = "testing...";
// options
// a function immediately change and update the dialogue
public void UpdateDialogue(string _newDialogue, string _newSpeaker, Color _speakerColor) ///THIS FUNCTION DOES NOT PROPERLY SET THE INFORMATION
{
// make sure root is enabled
tmp_Dialogue.text = _newDialogue; /// doing this or hard setting it here breaks the text
tmp_Dialogue.color = _speakerColor;
tmp_Speaker.text = _newSpeaker;
tmp_Speaker.color = _speakerColor;
print("Just passed: " + list_DialogueDict[int_DialogueID].dialogue); /// BUT THIS DOES PROPERLY PRINT THE INFORMATION
}
// a function to add dialogue to a list that needs to be read through
public void AddDialogueToQueue(string _newDialogue, string _newSpeaker, Color _speakerColor)
{
}
// Start is called before the first frame update
void Start()
{
///THESE ALL WORK WHEN IN THE START FUNCTION
//tmp_Dialogue.text = "hello| ";
//tmp_Dialogue.text = list_DialogueDict[int_DialogueID].dialogue;
//tmp_Dialogue.text = "hello| " + list_DialogueDict[int_DialogueID].dialogue;
//tmp_Dialogue.color = list_DialogueDict[int_DialogueID].speakerColor;
//tmp_Speaker.text = "test| " + list_DialogueDict[int_DialogueID].speaker;
//tmp_Speaker.color = list_DialogueDict[int_DialogueID].speakerColor;
/// THIS DOES NOT WORK ANYWHERE
UpdateDialogue(list_DialogueDict[int_DialogueID].dialogue, list_DialogueDict[int_DialogueID].speaker, list_DialogueDict[int_DialogueID].speakerColor); //ISSUE
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("space")) { int_DialogueID++; UpdateDialogue(list_DialogueDict[int_DialogueID].dialogue, list_DialogueDict[int_DialogueID].speaker, list_DialogueDict[int_DialogueID].speakerColor); }
}
}//end of UITextManager
// the custom list we'll use toe add dialogue
[System.Serializable]
public class DialogueDictionary
{
public string dialogue, speaker;
public Color speakerColor;
// maybe add an image / sprite to show on each speaker?
//maybe add font for each situation / speaker?
public DialogueDictionary(string _newDialogue, string _newSpeaker, Color _speakerColor)
{
dialogue = _newDialogue;
speaker = _newSpeaker;
speakerColor = _speakerColor;
}
}//end of dialogue dictionary