dd
This commit is contained in:
@@ -17,20 +17,29 @@ export class SkillCom extends CCComp {
|
||||
speed:number = 600;
|
||||
range:number = 80;
|
||||
scale:number = 1;
|
||||
atk:number = 10;
|
||||
is_destroy:boolean = false;
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
switch (selfCollider.group) {
|
||||
|
||||
case BoxSet.HERO_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
// this.reset()
|
||||
console.log('hero skill',selfCollider);
|
||||
if(this.is_destroy){
|
||||
return
|
||||
}else{
|
||||
this.is_destroy = true;
|
||||
this.toDestroy();
|
||||
}
|
||||
|
||||
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
@@ -40,6 +49,12 @@ export class SkillCom extends CCComp {
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.HERO:
|
||||
if(this.is_destroy){
|
||||
return
|
||||
}else{
|
||||
this.is_destroy = true;
|
||||
this.toDestroy();
|
||||
}
|
||||
// console.log('monster skill',selfCollider,otherCollider);
|
||||
// this.reset()
|
||||
break;
|
||||
@@ -57,7 +72,13 @@ export class SkillCom extends CCComp {
|
||||
this.node.setPosition(v3(this.node.position.x+deltaTime*this.speed*this.scale,this.node.position.y,this.node.position.z))
|
||||
if(Math.abs(this.node.position.x) > this.range)
|
||||
{
|
||||
this.reset()
|
||||
if(this.is_destroy){
|
||||
return
|
||||
}else{
|
||||
this.is_destroy = true;
|
||||
this.toDestroy()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -68,9 +89,14 @@ export class SkillCom extends CCComp {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
toDestroy() {
|
||||
setTimeout(() => {
|
||||
this.ent.destroy()
|
||||
}, 15);
|
||||
}
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.is_destroy=false
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user