Update NPC TMPro.text using sequencer
Posted: Sat Jun 18, 2022 10:41 pm
Hey Tony,
I'm trying to change the text of the TMPro component on an NPC via the sequencer by means of inputting a string in the sequencer. So I'm looking at something like this, SetTMPUI(NPCText, string).
I saw this on the forum but this required a preexisting Dialogue Manager variable to assign. I was trying to customize it to take in the string but failed to do so. As such, I was wondering if you know of a way I can go about doing this!
Thank you, love your package man. It enabled me to do so much more!
I'm trying to change the text of the TMPro component on an NPC via the sequencer by means of inputting a string in the sequencer. So I'm looking at something like this, SetTMPUI(NPCText, string).
I saw this on the forum but this required a preexisting Dialogue Manager variable to assign. I was trying to customize it to take in the string but failed to do so. As such, I was wondering if you know of a way I can go about doing this!
Tony Li wrote: ↑Mon Nov 23, 2020 10:18 am Hi Keiji,
You can do both in one sequencer command:
SequencerCommandSetTMPUI.csCode: Select all
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; namespace PixelCrushers.DialogueSystem.SequencerCommands { // Syntax: SetTMPUI(TMPObjectName, VariableName) public class SequencerCommandSetTMPUI : SequencerCommand { private void Awake() { var tmpObject = GetSubject(0); var variableName = GetParameter(1); if (tmpObject == null) { Debug.LogWarning("SetTMPUI(): Can't find GameObject '" + GetParameter(0) + "'"); } else if (string.IsNullOrEmpty(variableName) || !DialogueLua.DoesVariableExist(variableName)) { Debug.LogWarning("SetTMPUI(): There is no variable named '" + variableName + "'"); } else { var variableValue = DialogueLua.GetVariable(variableName).asString; var tmp = tmpObject.GetComponent<TextMeshPro>(); var tmpUGUI = tmpObject.GetComponent<TextMeshProUGUI>(); if (tmp != null) { tmp.text = variableValue; } else if (tmpUGUI != null) { tmpUGUI.text = variableValue; } else { Debug.LogWarning("SetTMPUI(): No TextMesh Pro component found on " + tmpObject, tmpObject); } } Stop(); } } }
Thank you, love your package man. It enabled me to do so much more!