lua - UserInputService 不适用于 roblox studio
问题描述
我想知道我做错了什么。
我只是按照文档使按“E”键在控制台上显示“打印”并说“按”但它没有用,我做错了什么?
-- input
local UserInputService = game:GetService("UserInputService")
--input
-- rolehandle
local function handletouched()
handle.Touched:Connect(function(fas)
wait(3)
role.Value = "-"
if game:GetService("UserInputService").InputBegan == Enum.KeyCode.E then
print("pressed")
end
end)
end
解决方案
您的代码没有太大意义。不确定您遵循了哪些文档。Roblox 文档及其示例非常清楚地说明了该做什么。
你定义了一个handletouched
永远不会被调用的函数。
在该函数中,您将事件对象与数字进行比较,这当然永远不会相等。
请阅读https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan
和
https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched
你有一个被游戏触发的事件,你必须提供一个事件处理函数。您实现该功能,然后将其连接到事件。因此,无论何时触发事件,都会调用此函数。
在实现自己的代码之前,您应该更仔细地阅读并首先尝试理解文档中给出的示例。
确保你明白这一点:
推荐阅读
- python - 贪婪的正则表达式向后看
- python-3.x - 如何使用 GlobalAveragePool 层作为模型的输出
- javascript - 未添加 Vue.js 过渡组 *-move 类
- ios - 无法加载网页并出现错误:操作无法完成。NSURLErrorDomain 错误 -999 将 Ionic 应用程序部署到 iOS 设备
- sql - 根据列值查找第二行数据,如果不可用则打印 NULL
- r - 将字符“pi”转换为值 pi
- python-3.x - 如何转换数据框中的所有浮点列,但第一列除外?
- vue.js - Vue cli 图像无法使用 webpack 加载
- c# - VB和C#之间的绑定问题
- spring - 转换对象 MethodSignature 时出错。春季AOP