• Create and register a new ScriptType. It returns new class type (constructor function), which is auto-registered to ScriptRegistry using its name. This is the main interface to create Script Types, to define custom logic using JavaScript, that is used to create interaction for entities.

    Parameters

    • name: string

      Unique Name of a Script Type. If a Script Type with the same name has already been registered and the new one has a swap method defined in its prototype, then it will perform hot swapping of existing Script Instances on entities using this new Script Type. Note: There is a reserved list of names that cannot be used, such as list below as well as some starting from _ (underscore): system, entity, create, destroy, swap, move, scripts, onEnable, onDisable, onPostStateChange, has, on, off, fire, once, hasEvent.

    • Optionalapp: AppBase

      Optional application handler, to choose which ScriptRegistry to add a script to. By default it will use Application.getApplication() to get current AppBase.

    Returns typeof ScriptType

    A class type (constructor function) that inherits ScriptType, which the developer is meant to further extend by adding attributes and prototype methods. Returns null if there was an error.

    var Turning = pc.createScript('turn');

    // define 'speed' attribute that is available in Editor UI
    Turning.attributes.add('speed', {
    type: 'number',
    default: 180,
    placeholder: 'deg/s'
    });

    // runs every tick
    Turning.prototype.update = function (dt) {
    this.entity.rotate(0, this.speed * dt, 0);
    };