Slash-The-Hordes/assets/Scripts/Game/Collision/WeaponCollisionSystem.ts
2022-11-28 12:19:04 +01:00

16 lines
506 B
TypeScript

import { Collider2D } from "cc";
import { Enemy } from "../Unit/Enemy/Enemy";
import { Weapon } from "../Unit/Player/Weapon/Weapon";
export class WeaponCollisionSystem {
private weapon: Weapon;
public constructor(weapon: Weapon) {
this.weapon = weapon;
weapon.Collider.ContactBeginEvent.on(this.onWeaponContactBegin, this);
}
private onWeaponContactBegin(otherCollider: Collider2D): void {
otherCollider.getComponent(Enemy).dealDamage(this.weapon.Damage);
}
}