pinball/assets/Scripts/ObstacleController.ts

31 lines
930 B
TypeScript
Raw Normal View History

2024-02-28 03:25:11 -08:00
import { _decorator, CCFloat, Component, Node, tween } from 'cc';
2024-02-27 18:19:33 -08:00
const { ccclass, property, float } = _decorator;
@ccclass('ObstacleController')
export class ObstacleController extends Component {
@property(Node)
private target: Node;
@property([Node])
private waypoints: Node[] = [];
@property(CCFloat)
private speed: number = 0;
2024-02-28 03:25:11 -08:00
protected start() {
2024-02-27 18:19:33 -08:00
//if (this.target !== null)
this.target.setPosition(this.waypoints[this.waypoints.length - 1].position);
this.followPath();
}
2024-02-28 03:25:11 -08:00
private followPath() {
2024-02-27 18:19:33 -08:00
const tweenPath = tween(this.target);
2024-02-28 03:25:11 -08:00
2024-02-27 18:19:33 -08:00
for (let i = 0; i < this.waypoints.length; i++) {
2024-02-28 03:25:11 -08:00
let a = tween(this.target).to(this.speed, { position: this.waypoints[i].getPosition() });
tweenPath.then(a);
2024-02-27 18:19:33 -08:00
}
// tweenPath.union().repeat(10)
2024-02-28 03:25:11 -08:00
tweenPath.union().repeatForever();
2024-02-27 18:19:33 -08:00
tweenPath.start();
}
2024-02-28 03:25:11 -08:00
}