Files
ball/assets/scripts/GoalDetector.ts

20 lines
583 B
TypeScript
Raw Normal View History

1970-01-01 08:45:37 +08:00
// 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");
}
}
}