mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-28 04:28:03 +00:00
15 lines
577 B
TypeScript
15 lines
577 B
TypeScript
import { Collider2D, Contact2DType } from "cc";
|
|
import { Item } from "../Items/Item";
|
|
import { ItemAttractor } from "../Items/ItemAttractor";
|
|
import { Magnet } from "../Unit/Player/Magnet";
|
|
|
|
export class MagnetCollisionSystem {
|
|
public constructor(magnet: Magnet, private itemAttractor: ItemAttractor) {
|
|
magnet.Collider.on(Contact2DType.BEGIN_CONTACT, this.onMagnetContactBegin, this);
|
|
}
|
|
|
|
private onMagnetContactBegin(_selfCollider: Collider2D, otherCollider: Collider2D): void {
|
|
this.itemAttractor.addItem(otherCollider.getComponent(Item));
|
|
}
|
|
}
|