46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { _decorator, Component, Node, Animation } from 'cc';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('WoodenManPlayer')
|
|
export class WoodenManPlayer extends Component {
|
|
private id: number = 0;
|
|
private isLocalPlayer: boolean = false;
|
|
private alive: boolean = true;
|
|
private animator: Animation = null;
|
|
|
|
init(id: number, isLocal: boolean) {
|
|
this.id = id;
|
|
this.isLocalPlayer = isLocal;
|
|
this.animator = this.getComponent(Animation);
|
|
|
|
// 确保动画组件存在
|
|
if (!this.animator) {
|
|
this.animator = this.addComponent(Animation);
|
|
}
|
|
}
|
|
|
|
getId(): number {
|
|
return this.id;
|
|
}
|
|
|
|
isAlive(): boolean {
|
|
return this.alive;
|
|
}
|
|
|
|
setAlive(alive: boolean) {
|
|
this.alive = alive;
|
|
}
|
|
|
|
// 播放死亡动画
|
|
playDieAnimation(callback?: () => void) {
|
|
if (this.animator) {
|
|
// 播放死亡动画
|
|
this.animator.play('player_die');
|
|
|
|
if (callback) {
|
|
// 动画播放完成后执行回调
|
|
this.animator.once(Animation.EventType.FINISHED, callback);
|
|
}
|
|
}
|
|
}
|
|
}
|