How to output text into UI
TextMeshPro (version without canvas)
Section titled “TextMeshPro (version without canvas)”UnityEngine = require("UnityEngine")TextMeshPro = require("TextMeshPro")
function Start() -- Bind the gameObject and use GetComponent local textGameObject = BoundObjects.textGameObject print(textGameObject) local textComponentFromGameObject = textGameObject.GetComponent("TMPro.TextMeshPro") print(textComponentFromGameObject)
-- Change text textComponentFromGameObject.text = "TextMeshPro - Success"endTextMeshPro (version with canvas)
Section titled “TextMeshPro (version with canvas)”UnityEngine = require("UnityEngine")TextMeshPro = require("TextMeshPro")
function Start() -- Bind the gameObject and use GetComponent local textGameObject = BoundObjects.textGameObject print(textGameObject) local textComponentFromGameObject = textGameObject.GetComponent("TMPro.TextMeshProUGUI") print(textComponentFromGameObject)
-- Change text textComponentFromGameObject.text = "TextMeshProUGUI - Success"endLegacy Unity UI Text (not recommended)
Section titled “Legacy Unity UI Text (not recommended)”UnityEngine = require("UnityEngine")
function Start() -- Bind the gameObject and use GetComponent local textGameObject = BoundObjects.textGameObject print(textGameObject) local textComponentFromGameObject = textGameObject.GetComponent("UnityEngine.UI.Text") print(textComponentFromGameObject)
-- Change text textComponentFromGameObject.text = "Text (Legacy) - Success"end