er2.bindKeyUp ▲ 42

Available from Easy Red 2 2.1.1

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 TypeDescription
voidTrue if the key was bound. False if the key name is unknown or the callback id is empty.

Parameters

ParameterTypeDescription
1stringThe key, as a Unity KeyCode name.
2stringThe 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")

Back to Scripting API