继承自:
会切换装备已有的工具
|
---|
已装备的的工具,模拟点击使用,会触发Activated事件。 |
local tool = script.Parent
tool.Equipped:Connect(function()
print("Equipped----")
end
)
tool.Unequipped:Connect(function()
print("Unequipped----")
end
)
tool.Activated:Connect(function()
print("Activated----")
end
)
tool.Deactivated:Connect(function()
print("Deactivated----")
end
)
tool.TouchBegin:Connect(function()
print("onTouchBegin----")
end
)
tool.TouchEnd:Connect(function()
print("onTouchEnd----")
end
)
local tool = script.Parent
local playersService = game:GetService("Players")
local localPlayer = playersService.LocalPlayer
local ContextActionService = game:GetService("ContextActionService")
local function testEquipTool(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.InputBegin.Value then
localPlayer:EquipTool( tool )
end
end
ContextActionService:BindAction(
"testEquipTool",
testEquipTool,
Enum.ContextActionType.KeyBoard.Value,
string.byte('X') )
local function testUnequipTool(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.InputBegin.Value then
localPlayer:UnequipTools()
end
end
ContextActionService:BindAction(
"testUnequipTool",
testUnequipTool,
Enum.ContextActionType.KeyBoard.Value,
string.byte('Z') )