Skip to content

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.

csharp
class Spinner : Component {
    [Property] [Range(0, 360)] float Speed = 90;

    void Update(float dt) {
        Transform.Rotate(Speed * dt);
    }
}

Setup ​

  1. Open Scripts → New Behavior. You get a starter class with empty Start and Update.
  2. Replace it with the class above. Save & Apply (Cmd/Ctrl+S).
  3. In Arrange, select a visible object → Add Component → Spinner.
  4. 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 ​

MethodWhen
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 ​