Your first OpalScript component
Same spinner as High-level scripting, walked a little slower. One file, one class, derived from Component. No input map, no extra components — attach it, press Play, watch it turn.
class Spinner : Component {
[Property] [Range(0, 360)] float Speed = 90;
void Update(float dt) {
Transform.Rotate(Speed * dt);
}
}Setup
- Open Scripts → New Behavior. You get a starter class with empty
StartandUpdate. - Replace it with the class above. Save & Apply (
Cmd/Ctrl+S). - In Arrange, select a visible object → Add Component → Spinner.
- Press Play. Drag Speed in the Inspector while it is spinning.
The Script Studio tutorial Your First OpalScript Component inserts this same class.
Speed in the Inspector
[Property] puts Speed on the object and saves it. Attach the spinner to two sprites and give them different speeds — they do not share the field.
[Range(0, 360)] only limits the slider. Code can still set Speed to 400.
A field without [Property] is this Play session's memory. It will not show in the Inspector and will not save. public is a different switch: it lets other scripts see the field, Inspector or not.
What the engine calls
| Method | When |
|---|---|
void Start() | Once at Play, after physics is ready |
void Update(float dt) | Every gameplay frame. dt is seconds |
void OnTap() | This object was tapped during Play |
There is also FixedUpdate (right before each physics step) and End (when you Stop). You do not need them for a spinner.
Transform uses pixels and degrees. Stage +Y is down.
Next
- More copy-paste classes: High-level scripting
- A complete game on this track: Flap
- Named input actions (
Input.Vector,Input.Pressed): Input - GameState (
Game.GetNumber/SetNumber): Game, Variables - Language, collisions,
[Sync]: Language, Lifecycle, Multiplayer