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); } }