import { _decorator, Component, Animation } from 'cc'; const { ccclass } = _decorator; @ccclass('oneCom') export class oneCom extends Component { private anim: Animation | null = null; start() { this.anim = this.node.getComponent(Animation); if (!this.anim) { this.node.destroy(); return; } this.anim.off(Animation.EventType.FINISHED, this.onAnimationFinished, this); this.anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this); } onDestroy() { if (!this.anim) return; this.anim.off(Animation.EventType.FINISHED, this.onAnimationFinished, this); this.anim = null; } onAnimationFinished() { this.node.destroy(); } }