【问题标题】:Roblox - How would I make a script that closes an open GUI when another is opened?Roblox - 当打开另一个 GUI 时,我将如何制作一个关闭打开的 GUI 的脚本?
【发布时间】:2016-05-26 23:19:21
【问题描述】:

我有两个 GUI,每个 GUI 都由屏幕顶部的一个按钮打开,但我想这样做,如果有人试图在第一个打开的情况下打开第二个 GUI,它会在打开之前关闭第一个第二个。

【问题讨论】:

    标签: user-interface scripting roblox


    【解决方案1】:

    您可以执行以下操作:

    local frames = {
        [buttonA] = frameA;
        [buttonB] = frameB;
    }
    for button,frame in pairs(frames) do
        button.MouseButton1Click:connect(function()
            if frame.Visible then
                -- If we try to reopen the current frame, close it
                frame.Visible = false
                return
            end
            -- Close all frames and make ours visible
            for k,v in pairs(frames) do
                -- 'v == frame' is true if it's our frame
                v.Visible = v == frame
            end
        end)
    end
    

    您还应该查看ROBLOX Wiki。它有一些很好的 Lua 教程和诸如打开/关闭 GUI 之类的东西。

    【讨论】:

    • 谢谢,但我真的不知道该怎么做。如果有帮助,screenGUI 的名称是 GameUpdateLog、Instructions 和 GamepassShop。里面的框架是 UpdateLog、ShopInterface 和 InsInterface。这些按钮也称为 OpenLog、OpenInstructions 和 OpenShop。
    • 你为什么不把所有东西都放在一个screengui中呢?然后你就做[gui.OpenLog] = gui.UpdateLog, [gui.OpenInstructions] = gui.InsInterface, etc
    【解决方案2】:

    100% 有效 制作一个打开和关闭的 gui...把这个脚本: FIRSTGUINAME 是你的第一个 gui,重命名它, SECONDGUINAME 是你的第二个 gui 名称...

    FIRSTGUINAME = script.Parent -- 非常重要的分类信息 SECONDGUINAME = script.Parent.Parent.Parent:WaitForChild(你的第二个 GUI)

    FIRSTGUINAME.MouseButton1Click:connect(function() SECONDGUINAME.Visible = 不可见

    就是这样,现在只需复制粘贴这个和你的设置

    【讨论】:

      【解决方案3】:

      如果您想在另一个 GUI 处于打开状态时关闭 GUI,您可以尝试以下代码:

      GUI1 = (insert)
      GUI2 = (insert)
      
      GUI.MouseButton1Click:connect(function()
      if GUI1.Visible == false then
      if GUI2.Visible == true then
      GUI2.Visible = false
      GUI1.Visible = true
      else
      GUI.Visible = true
      end
      else 
      GUI1.Visible = false
      end
      

      如果您对补间的花哨事物感兴趣,您可能需要自己进行研究。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-18
        • 2021-07-04
        • 2019-09-04
        • 2020-05-16
        • 2019-06-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多