local ui, root =GUI:npcUI("shijieditu")
if GUI:Win_IsNotNull(ui.Button_1) then
GUI:addOnClickEvent(ui.Button_1, function()
SL:print("点击了第1个按钮")
GUI:delayTouchEnabled(ui.Button_1, 0.2)
SL:SendLuaNetMsg(5800
根据浮生梦老师前端课程内容,要实现转生等级≥5时显示按钮和特效,可以这样编写代码:
```lua
local ui, root = GUI:npcUI("shijieditu")
-- 获取当前转生等级
local reLevel = SL:GetMetaValue("RELEVEL") or 0
-- 判断转生等级是否≥5
if reLevel >= 5 then
-- 显示Button_1
if GUI:Win_IsNotNull(ui.Button_1) then
GUI:setVisible(ui.Button_1, true)
GUI:addOnClickEvent(ui.Button_1, function()
SL:print("点击了第1个按钮")
GUI:delayTouchEnabled(ui.Button_1, 0.2)
SL:SendLuaNetMsg(58003, 0, 33, 0, 0)
end)
end
-- 显示Effect_1
if GUI:Win_IsNotNull(ui.Effect_1) then
GUI:setVisible(ui.Effect_1, true)
end
else
-- 转生等级<5时隐藏
if GUI:Win_IsNotNull(ui.Button_1) then
GUI:setVisible(ui.Button_1, false)
end
if GUI:Win_IsNotNull(ui.Effect_1) then
GUI:setVisible(ui.Effect_1, false)
end
end
```
**代码说明:**
1. 使用 `SL:GetMetaValue("RELEVEL")` 获取当前转生等级
2. 通过 `GUI:setVisible(widget, value)` 控制控件显示/隐藏
3. 使用 `GUI:Win_IsNotNull()` 判断控件是否存在,避免空指针错误
4. 转生等级≥5时显示按钮和特效,否则隐藏
**注意:** 如果界面中没有 `Effect_1` 这个控件,需要先在界面编辑器中创建,或者通过 `GUI:Effect_Create()` 函数动态创建特效。
这个逻辑可以放在界面打开时执行,确保每次打开界面都会根据当前转生等级更新显示状态。