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
| Member | Description |
|---|---|
| Input.Axis | Read a named project input action as an axis. |
| Input.Vector | Read a named project input action as a vector. |
| Input.Held | Is a named input action held? |
| Input.Pressed | Was a named input action pressed this frame? |
| Input.Released | Was 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));
}
}