using UnityEngine; using UnityEngine.EventSystems; namespace GameFramework { /// /// 挂到 MainMenu 场景的 EventSystem 上(或和它同一个空物体上), /// 让 EventSystem 通过 DontDestroyOnLoad 跨场景存活。 /// 这样 Gameplay、Scoring 等场景的按钮都能正常响应点击。 /// /// 如果场景里没有 EventSystem,也可以挂到任意空物体上, /// 脚本会自动创建一个。 /// public class PersistentEventSystem : MonoBehaviour { void Awake() { // 如果场景里没有 EventSystem,自动创建 if (FindObjectOfType() == null) { var go = new GameObject("EventSystem"); go.AddComponent(); go.AddComponent(); } // 让 EventSystem 跨场景存活 var eventSystem = FindObjectOfType(); if (eventSystem != null) DontDestroyOnLoad(eventSystem.gameObject); } } }