dd
This commit is contained in:
58
assets/script/game/skills/baseCom.ts
Normal file
58
assets/script/game/skills/baseCom.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { _decorator, Component, Node, tween ,Vec3,v3,Collider2D,Contact2DType} from 'cc';
|
||||
import { BoxSet } from '../common/config/BoxSet';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('baseCom')
|
||||
export class baseCom extends Component {
|
||||
speed:number = 600;
|
||||
range:number = 80;
|
||||
scale:number = 1;
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
|
||||
switch (selfCollider.group) {
|
||||
case BoxSet.HERO_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
// this.reset()
|
||||
console.log('hero skill',selfCollider,otherCollider);
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.HERO:
|
||||
// console.log('monster skill',selfCollider,otherCollider);
|
||||
// this.reset()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
change_collider_group(group:number){
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = group;
|
||||
}
|
||||
update(deltaTime: number) {
|
||||
this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
|
||||
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.node.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user