【问题标题】:Roblox ContextAction trigers twiceRoblox 上下文操作触发两次
【发布时间】:2019-12-19 00:26:37
【问题描述】:

我尝试使用 Roblox ContextActionService 在 roblox for mobile 中创建一个按钮,但是当我按下 gui 按钮时它会触发,当我释放它时它也会触发我希望它在我按下按钮时触发一次

function tpggle()
    print("L pressed")
end
ContextActionService:BindAction("ToggleLight", tpggle, true, Enum.KeyCode.L)
ContextActionService:SetTitle("ToggleLight","L")
ContextActionService:SetPosition("ToggleLight",UDim2.new(1, -97,1, -133))

I expected:
  L pressed
I got:
  L pressed(x2)

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    您的操作处理程序tqggle 很可能被调用了两次。一次按下按钮,一次释放按钮。

    试试这个:

    function tpggle(actionName, inputState, inputObj)
      if inputState == Enum.UserInputState.Begin then 
        print("L pressed")
      end  
    end
    

    所以它只会在你按下按钮时打印一些东西。

    参考

    https://developer.roblox.com/en-us/api-reference/function/ContextActionService/BindAction

    https://developer.roblox.com/en-us/api-reference/property/InputObject/UserInputState

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 2019-07-19
      • 2018-10-28
      • 2015-05-17
      • 2014-03-04
      相关资源
      最近更新 更多