// 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"); } } }