A与B两个节点碰撞,A节点被攻击销毁,B节点离开,可是两个节点的持续碰撞回调还在继续
Collider1.on(‘onTriggerEnter’, this.onTrigger, this);
Collider1.on(‘onTriggerExit’, this.onTrigger1, this);
Collider1.on(‘onTriggerStay’, this.onTrigger2, this);
private onTrigger(event: ITriggerEvent) {//碰撞开始
if (event.otherCollider.node.name == “ant0” || this.colliderName == “ant1”) {
this.animator.play("attack")
log("碰撞ant1")
}
if (event.otherCollider.node.name == "sce14") {
this.animator.play("attack")
log("碰撞sce14")
}
}
private onTrigger1(event: ITriggerEvent) {//碰撞结束
if (event.otherCollider.node.name == "ant0" || this.colliderName == "ant1") {
log("离开")
Tween.stopAllByTarget(this.node)
let anim = this.node.getComponent("Enemy")!.animator
anim.play("run")
tween(this.node)
.to(2, { position: new Vec3(0, 0, 0) }, {
easing: 'linear', onComplete: () => {
this.animator.play("attack")
}
})
.union()
.repeat(1)
.start();
}
}
public onTrigger2(event: ITriggerEvent) {//碰撞持续
if (event.otherCollider.node.name == "ant0" || this.colliderName == "ant1") {
if (this.animator.getState("attack").isPlaying === true) {
this.animator.on('lastframe', this.antFinished, this);
} else {
this.animator.off('lastframe', this.antFinished, this);
}
}
if (event.otherCollider.node.name == "sce14") {
if (this.animator.getState("attack").isPlaying === true) {
this.animator.on('lastframe', this.onFinished, this);
} else {
this.animator.off('lastframe', this.onFinished, this);
}
}
}