20 lines
691 B
TypeScript
20 lines
691 B
TypeScript
import { _decorator, CCInteger, Collider2D, Component, Contact2DType, Node } from 'cc';
|
|
import { GameManager } from '../Manager/GameManager';
|
|
const { ccclass, property, float } = _decorator;
|
|
|
|
@ccclass('Goal')
|
|
export class Goal extends Component {
|
|
@property({ type: Collider2D, visible: true })
|
|
private _collider: Collider2D;
|
|
@property({ type: CCInteger, visible: true })
|
|
private _score: number;
|
|
|
|
protected onLoad(): void {
|
|
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this);
|
|
}
|
|
|
|
private onContactBegin(selfCollider: Collider2D, otherCollider: Collider2D) {
|
|
GameManager.instance.goal(this._score, otherCollider.node);
|
|
}
|
|
}
|