role 也转为使用hero 预制体
This commit is contained in:
@@ -15,12 +15,13 @@ export class BoxRangComp extends CCComp {
|
||||
box_group:number = BoxSet.DEFAULT;
|
||||
box_tag:number = BoxSet.ATK_RANGE;
|
||||
offset_x:number = 0;
|
||||
atk_range:number = 150;
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
collider.tag = this.box_tag;
|
||||
collider.offset = v2(this.offset_x,0);
|
||||
// collider.offset = v2(this.offset_x,40);
|
||||
this.Hero_node = this.node.parent;
|
||||
this.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp);
|
||||
// console.log("range box",this.MonsterViewComp);
|
||||
@@ -42,9 +43,11 @@ export class BoxRangComp extends CCComp {
|
||||
// }
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0 ){
|
||||
// console.log(this.node.name+"onEndContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
|
||||
this.MonsterViewComp.is_atking = false;
|
||||
this.MonsterViewComp.enemy = null;
|
||||
}
|
||||
}
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
@@ -53,9 +56,17 @@ export class BoxRangComp extends CCComp {
|
||||
let other_pos = otherCollider.node.getWorldPosition() ;
|
||||
let self_pos = this.node.getWorldPosition();
|
||||
// console.log("onPreSolve:",self_pos,other_pos);
|
||||
if(Math.abs(other_pos.x-self_pos.x) < BoxSet.ATK_RANGE_X){
|
||||
if(this.MonsterViewComp.enemy==null){
|
||||
this.MonsterViewComp.enemy = otherCollider.node;
|
||||
}else{
|
||||
if(this.MonsterViewComp.enemy.isValid==false){
|
||||
this.MonsterViewComp.enemy = otherCollider.node;
|
||||
}
|
||||
}
|
||||
if(Math.abs(other_pos.x-self_pos.x) < this.atk_range){
|
||||
|
||||
this.MonsterViewComp.is_atking = true;
|
||||
// this.MonsterViewComp.stop_cd = 0.1
|
||||
this.MonsterViewComp.stop_cd = 0.1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user