using UnityEngine; using System.Collections; public class StartManager : MonoBehaviour { public static StartManager Instance; [Header("开场 UI")] public GameObject startCanvas; public GameObject backgroundCanvas; public bool gameStarted = false; public bool isOnStartScreen = true; public bool isTransitioning = false; // ← public void Awake() { Instance = this; } void Start() { gameStarted = false; isOnStartScreen = true; isTransitioning = false; if (startCanvas != null) startCanvas.SetActive(true); if (backgroundCanvas != null) backgroundCanvas.SetActive(false); Time.timeScale = 0f; Debug.Log("✅ StartManager 初始化完成"); } public void PressStart() { if (gameStarted) return; if (isTransitioning) return; Debug.Log("✅ PressStart 被调用"); StartCoroutine(StartSequence()); } IEnumerator StartSequence() { isTransitioning = true; isOnStartScreen = false; if (startCanvas != null) startCanvas.SetActive(false); Debug.Log("✅ StartCanvas 已隐藏"); if (backgroundCanvas != null) backgroundCanvas.SetActive(true); Debug.Log("✅ BackgroundCanvas 已显示"); // 用 unscaledDeltaTime 计时 // 不受 timeScale 影响 float elapsed = 0f; while (elapsed < 5f) { elapsed += Time.unscaledDeltaTime; yield return null; } if (backgroundCanvas != null) backgroundCanvas.SetActive(false); gameStarted = true; isTransitioning = false; Time.timeScale = 1f; Debug.Log("✅ 游戏正式开始!"); } }