first commit
This commit is contained in:
19
assets/scripts/GoalDetector.ts
Normal file
19
assets/scripts/GoalDetector.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// assets/scripts/GoalDetector.ts
|
||||
import { _decorator, Component, ITriggerEvent } from "cc";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GoalDetector")
|
||||
export class GoalDetector extends Component {
|
||||
@property({ tooltip: "GameManager 节点(接收进球事件)" }) gameManagerPath =
|
||||
"";
|
||||
|
||||
onTriggerEnter(event: ITriggerEvent) {
|
||||
const other = event.otherCollider?.node;
|
||||
if (!other) return;
|
||||
if (other.name.includes("Ball")) {
|
||||
// 简单通知
|
||||
const gm = this.node.scene.getChildByPath(this.gameManagerPath);
|
||||
gm?.emit("GOAL");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user