er2.bindKeyUp 42
Same as bindKey, but the callback runs when the key is released. A key can have both a press and a release callback.
Return value
| Return Type | Description |
|---|---|
| void | True if the key was bound. False if the key name is unknown or the callback id is empty. |
Parameters
| Parameter | Type | Description |
|---|---|---|
| 1 | string | The key, as a Unity KeyCode name. |
| 2 | string | The id of a callback registered with er2.setCallback. |
Examples
A key that calls artillery
-- F5 fires a barrage on the player's position, once every 30 seconds
local nextBarrage = 0
er2.setCallback("barrage", function()
if er2.time() < nextBarrage then
er2.print("Artillery is reloading")
return
end
nextBarrage = er2.time() + 30
local player = er2.getPlayer()
if player ~= nil then
local p = player:getPosition()
er2.explosion(vec3(p.x, p.y, p.z + 25), 400, 20, 12)
end
end)
er2.bindKey("F5", "barrage")
-- the key is released when the mission no longer needs it
-- er2.unbindKey("F5")