代码如下,一直到‘block销毁啦’都还正常,然后就报错了。是不是销毁节点前还需要一些善后工作?
@property(Label)
label = null;
blood = 0;
start() {
this.blood = Math.ceil(random() * 10);
this.label.getComponent(Label).string = this.blood;
let collider = this.node.getComponent(Collider2D);
collider.restitution = 1 ;
collider.friction = 0;
//碰撞回调
if (this.getComponent(Collider2D)) {
this.getComponent(Collider2D).on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
}
}
onBeginContact(){
this.blood -= 1;
if(this.blood != 0) {
this.label.getComponent(Label).string = this.blood;
}else{
console.log('block销毁啦');
this.node.destroy();
}
}
报错如下: