通过 UserWidget.NewWidgetObjectBP 实例化 Widget 蓝图后,如果立即访问其中的控件,会得到 nil。需要先通过 AddChildToCanvas 把 Widget 挂到 Canvas,再访问内部控件。
-- 实例化 Widget
local tipWidget = UserWidget.NewWidgetObjectBP(pc, self.ScoreFloatUIClass)
-- 先挂到容器
local slot = self.Canvas_ScoreFloat:AddChildToCanvas(tipWidget)
if slot then
slot:SetAutoSize(true)
slot:SetAlignment(Vector2D.New(0.5, 0.5))
local rx = (math.random() - 0.5) * 30
local ry = (math.random() - 0.5) * 40
slot:SetPosition(Vector2D.New(rx, ry))
end
-- 挂到 Canvas 后才能访问 Text_Score
tipWidget.Text_Score:SetText("+" .. tostring(score))
Discussion
留言讨论
发表留言时,评论服务会记录必要的 IP 与 User-Agent 信息,用于安全审核和防止滥用。