消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
1.3 KiB

import { _decorator, Collider2D, Component, Contact2DType, IPhysics2DContact, Node } from 'cc';
import { SuDace } from './SuDace';
import { SuDaceEnemy } from './SuDaceEnemy';
const { ccclass, property } = _decorator;
@ccclass('SudaceSkill')
export class SudaceSkill extends Component {
@property
damage = 1;
start() {
}
update(deltaTime: number) {
}
private _col: Collider2D = null;
protected onEnable(): void {
this._col = this.node.getComponent(Collider2D);
this._col?.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
protected onDisable(): void {
this._col?.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
private onBeginContact(self: Collider2D, other: Collider2D, contact: IPhysics2DContact | null) {
if (!this.node.active || !other?.node?.active) return;
const otherName = other.node.name.toLowerCase();
if (otherName === "enemy" || otherName.includes("enemy")) {
this.hitEnemy(other.node);
}
}
private hitEnemy(enemy: Node) {
if (!this.node.active || !enemy?.active) return;
enemy.getComponent(SuDaceEnemy)?.hit(this.damage);
SuDace.instance?.recycleBullet(this.node);
}
}