roblox studio 中的用户界面问题

问题描述 投票:0回答:1

我为播放器制作了一个设置 GUI,用于切断音乐或打开音乐,唯一的问题是 GUI 默认显示

我尝试移动代码或将 true 设置为 false...但没有任何效果,我将添加下面的代码

local open = true

script.Parent.MouseButton1Click:Connect(function()
    if open == true then
        open = false
        script.Parent.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0.278, 0,0.319, 0), "InOut", "Quad", 0.5, true)
    else
        open = true
        script.Parent.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0.278, 0,1, 0), "InOut", "Quad", 0.5, true)
    end
end)
user-interface lua roblox
1个回答
0
投票

你如何向玩家展示 GUI?

  • 如果您将其放入 StarterGui 中,游戏将通过将 GUI 克隆到玩家的 PlayerGui 文件夹中来自动处理此问题,该文件夹将自动显示 GUI。
  • 如果您自己这样做,您可能会忘记 ScreenGui 已启用并在克隆到播放器的 PlayerGui 文件夹时显示。

这也意味着打开 .Visibile 属性的后续帧也将自动显示。

总而言之,这意味着 GUI 设置为首先显示其父级。

为了解决这个问题,您可能希望本地脚本也能控制 ScreenGui 和您想要显示的框架的适当属性。

例如

local mainFrame = script.Parent.Parent.Parent.MainFrame
local open = true

script.Parent.MouseButton1Click:Connect(function()
    if open == true then
        open = false
        mainFrame:TweenPosition(UDim2.new(0.278, 0,0.319, 0), "InOut", "Quad", 0.5, true)
        task.wait(0.5)
        mainFrame.Visible = false
    else
        open = true
        mainFrame.Visible = true
        mainFrame:TweenPosition(UDim2.new(0.278, 0,1, 0), "InOut", "Quad", 0.5, true)
    end
end)

当然,也可能是框架的起始位置设置不正确导致您当前遇到的问题。您必须在 GUI 编辑模式中设置它,或者在本地脚本的开头设置它:

...
mainFrame.Position = UDim2.new(0.278, 0,0.319, 0)
...
-- the rest of the code
...
© www.soinside.com 2019 - 2024. All rights reserved.