31 lines
993 B
TypeScript
31 lines
993 B
TypeScript
|
import { _decorator, CCFloat, Component, log, Node, randomRange, Tween, tween, Vec2, Vec3 } from 'cc';
|
||
|
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;
|
||
|
|
||
|
protected start() {
|
||
|
//if (this.target !== null)
|
||
|
this.target.setPosition(this.waypoints[this.waypoints.length - 1].position);
|
||
|
|
||
|
this.followPath();
|
||
|
}
|
||
|
|
||
|
private followPath() {
|
||
|
const tweenPath = tween(this.target);
|
||
|
|
||
|
for (let i = 0; i < this.waypoints.length; i++) {
|
||
|
let a = tween(this.target).to(this.speed,{position: this.waypoints[i].getPosition()})
|
||
|
tweenPath.then(a)
|
||
|
}
|
||
|
// tweenPath.union().repeat(10)
|
||
|
tweenPath.union().repeatForever()
|
||
|
tweenPath.start();
|
||
|
}
|
||
|
}
|