Skip to content

How to output text into UI

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"
end
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"
end
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