我正在制作一个ROBLOX游戏,我有一个GUI问题:
我甚至不想要“游戏装.”为了显示出来,我只在学习按钮的细节时才把它放在那里。
我的GUI只是“开始”菜单,所以当您单击“开始游戏”时,GUI应该会消失,您将被加载到实际的游戏中。
下面是我为按钮的脚本准备的内容:
local button = script.Parent
local toggled = false
local function onButtonActivated()
if toggled == false then
button.Text = "Game Loading..."
toggled = true
else
button.Text = "Start Game"
toggled = false
end
end
button.Activated:Connect(onButtonActivated)
注意:我通过IntelliJ使用Lua (ROBLOX的默认语言),并将我完成的代码复制到脚本中,因为IntelliJ的文本编辑器比ROBLOX的默认编辑器好得多。
发布于 2020-07-15 02:16:46
如果这个地方只是一个带有开始菜单的中心,而实际的游戏在宇宙的其他地方,那么您需要使用TeleportService:Teleport()
将LocalPlayer
移动到该游戏中。在传送完成后,玩家就可以在没有问题的情况下玩那个游戏了。下面是一个使用代码示例的示例:
local button = script.Parent
local toggled = false
local destination = 0 -- Change 0 to the place ID you want the user to be teleported to
local TeleportService = game:GetService("TeleportService")
local function onButtonActivated()
if toggled == false then
button.Text = "Game Loading..."
--toggled = true
TeleportService:Teleport(destination)
else
button.Text = "Start Game"
toggled = false
end
end
button.Activated:Connect(onButtonActivated)
但是,如果您要在实际游戏中加载这个GUI,那么您所需要做的就是:Destroy()
这个GUI对象。这将永久地将GUI对象及其所有子对象移动到nil
下,并断开所有连接。
在游戏中,这将意味着GUI简单地消失,玩家将能够继续玩游戏。除非您在GUI中运行了其他关键代码,否则如果您只使用一个地方,这应该是最佳解决方案。
local button = script.Parent
local toggled = false
local guiObj = nil -- Replace nil with a reference to the "ScreenGui/BillboardGUI" object that houses the 'button'.
local function onButtonActivated()
if toggled == false then
--[[button.Text = "Game Loading..."
toggled = true]]--
guiObj:Destroy()
else
button.Text = "Start Game"
toggled = false
end
end
button.Activated:Connect(onButtonActivated)
发布于 2020-08-06 21:55:54
local button = script.Parent
local guiObj = --a reference to the main screengui which the button is a descendant of
local function onButtonClicked()
guiObj:Destroy()
end
button.MouseButton1Click:Connect(onButtonClicked)
如果你想的话,你可以做一些花哨的褪色之类的事情。
https://stackoverflow.com/questions/62902336
复制相似问题