一个例子是这样的
local E = game:GetService('UserInputService').SetKeyDown(Enum.KeyCode.E) 但它当然不能工作,因为我不能让我的游戏本身按下E,所以它需要更长的时间,如果你找到了解决方案,你也可以在它按下的地方做一个吗?
发布于 2021-09-07 06:51:51
输入只能在客户端注册,因此您必须在LocalScript中编写代码。有两个服务用来获取玩家的输入:
本示例使用UserInputService获取播放器的LeftMouseButton输入。
local UserInputService = game:GetService("UserInputService")
local function onInputBegan(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("The left mouse button has been pressed!")
end
end
UserInputService.InputBegan:Connect(onInputBegan)这个示例正确地展示了如何使用ContextActionService将用户输入绑定到上下文操作。上下文是装备的工具;动作是重新加载一些武器。
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Reload"
local tool = script.Parent
local function handleAction(actionName, inputState, inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Reloading!")
end
end
tool.Equipped:Connect(function ()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)你应该看看维基页面。
发布于 2021-09-11 00:01:04
听起来您想要编写一个按E键的脚本,但这是不可能的。
您可以将操作绑定到按键,就像Giant427提供的示例一样,也可以手动调用绑定到这些操作的函数,但不能编写脚本来触发键盘输入。
https://stackoverflow.com/questions/69075785
复制相似问题