Roblox Studio-GUI的关键切换 [英] Roblox Studio - Key Toggle for GUI

查看:242
本文介绍了Roblox Studio-GUI的关键切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我目前正在Roblox Studio中制作一个项目.我有一个Frame GUI,我想让它在玩家运行游戏时拥有GUI的位置时,可以按下某个键将其切换为(ON)和(OFF).因此,一个打开/关闭系统.而不是使用鼠标单击,我想要一个按键切换.关于如何执行此操作的任何想法?

Alright so I am currently making a project in Roblox Studio. And I have a Frame GUI, I want to make it where when a player has the gui when they're running the game, that they can press a certain key to toggle it (ON) and (OFF). So a Open/Close System. Instead of using a Mouse Click I want a key toggle. Any idea on how to do this?

推荐答案

http://wiki.roblox.com/index.php?title=键盘输入 该链接说明了2种方法,更好的方法是在顶部或此处:

http://wiki.roblox.com/index.php?title=Keyboard_input This link explains 2 ways, the better way is the top or here:

local toggle = false -- false is Off; true is On


function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        print("R was pressed")
        if toggle == false then
             toggle = true
              -- INSERT Making GUI Visible
        else
            toggle = false
            -- INSERT making GUI Invisible
        end
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)

-上面的行也可以写为:
-game.ContextActionService:BindAction("keyPress",onKeyPress,false,"r")

-- The above line could also been written as:
-- game.ContextActionService:BindAction("keyPress", onKeyPress, false, "r")

这篇关于Roblox Studio-GUI的关键切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆