29 lines
758 B
TypeScript
29 lines
758 B
TypeScript
import { _decorator, Component, Node } from 'cc';
|
|
import { UmUtil } from '../../../../cc-common/cc-util/UmUtil';
|
|
import { Vec3 } from 'cc';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('BossMove')
|
|
export class BossMove extends Component {
|
|
target = 240;
|
|
isLeft = false;
|
|
targetPoint = Vec3.ZERO;
|
|
speed = 1 / 200;
|
|
|
|
protected start(): void {
|
|
this.targetPoint = this.node.position;
|
|
this.move();
|
|
}
|
|
|
|
move()
|
|
{
|
|
this.targetPoint = new Vec3(this.isLeft ? -240 : 240, this.targetPoint.y, 0);
|
|
UmUtil.moveTo(this.node, this.targetPoint, Vec3.distance(this.targetPoint, this.node.position) * this.speed, 0, () => {
|
|
this.isLeft = !this.isLeft;
|
|
this.move();
|
|
});
|
|
}
|
|
|
|
}
|
|
|