Skip to content

Input ​

class in OpalScript

Read button, axis and vector actions configured in Settings → Project Input.

Configure them in Settings → Project Input first: Jump · Space creates a Button action for the example below, which also needs Rigid Body 2D (Dynamic) and Collider 2D. Strings match a stable action ID or a unique, case-sensitive action name. Actions.Jump uses a compiler-checked project binding when available. Pressed/Released are edges; Held stays true while down. Unknown or inactive actions return false or zero.

Methods ​

MemberDescription
Input.AxisRead a named project input action as an axis.
Input.VectorRead a named project input action as a vector.
Input.HeldIs a named input action held?
Input.PressedWas a named input action pressed this frame?
Input.ReleasedWas a named input action released this frame?

Example ​

csharp
class Hopper : Component {
    [Property] float JumpSpeed = 420;

    void Update(float dt) {
        if (!Input.Pressed("Jump")) return;
        RigidBody2D body = GetComponent<RigidBody2D>();
        if (body != null) body.SetVelocity(new Vector2(body.Velocity.X, -JumpSpeed));
    }
}

See also ​