Home Game Development Import different courses – Cocos Creator

Import different courses – Cocos Creator

0
Import different courses – Cocos Creator

[ad_1]

What is the very best recommendation on importing a customisable class to make use of its strategies right into a script ?

I would love for example to have Controller.ts in a single prefab and that this class can entry strategies from a generic Movements.ts in several cases.

    // as ES5 import ?
import { ES5Movements } from "./Velocity/Movements";
const { ccclass, property } = _decorator;

@ccclass("Controller")
export class Controller extends Component {
  actions: Movements;

  // As property ?
  @property({ sort: Script })
  ScriptMovements: Script;

  onLoad() {
    // or as part ?
    this.actions = this.getComponent(Movements);
  }

// ... later
  onKeyDown(occasion: EventKeyboard) {
        this.actions.moveLeft();
}

The factor is that I wish to have a special Movements class for each prefab occasion, so importing will trigger duplication of Controller.js. As property appears to not work and getComponent is flaky

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here