<解決Q30>
This commit is contained in:
parent
d0f3e2e70b
commit
1fe6a92210
@ -1,4 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
@ -11,6 +11,10 @@ public class ClientGameBackToRealSceneController : MonoBehaviour
|
||||
public VideoPlayer videoPlayer;
|
||||
public RawImage videoDisplay;
|
||||
|
||||
// --- 【新增變數】用於追蹤兩個條件是否滿足 ---
|
||||
private bool isVideoFinished = false;
|
||||
private bool isSignalReceived = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
@ -35,7 +39,7 @@ public class ClientGameBackToRealSceneController : MonoBehaviour
|
||||
// 設置影片結束事件
|
||||
videoPlayer.loopPointReached += OnVideoFinished;
|
||||
|
||||
// 設置影片顯示
|
||||
// 設置影片顯示 (略)
|
||||
if (videoDisplay != null)
|
||||
{
|
||||
videoPlayer.targetTexture = null;
|
||||
@ -47,13 +51,43 @@ public class ClientGameBackToRealSceneController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// 影片播放結束時呼叫
|
||||
void OnVideoFinished(VideoPlayer vp)
|
||||
{
|
||||
Debug.Log("影片播放完成,準備跳轉");
|
||||
if (!string.IsNullOrEmpty(ClientLastWordsSceneController.words))
|
||||
Debug.Log("影片播放完成。");
|
||||
isVideoFinished = true; // 影片結束標記設為 true
|
||||
CheckAndLoadScene(); // 檢查是否可以跳轉
|
||||
}
|
||||
|
||||
// --- 【新增方法】供 ClientMessageHandler 呼叫,標記訊號已收到 ---
|
||||
public void ReceiveSignalFromPlayerB()
|
||||
{
|
||||
Debug.Log("收到玩家B的訊號 (gameFinalWords)。");
|
||||
isSignalReceived = true; // 訊號接收標記設為 true
|
||||
CheckAndLoadScene(); // 檢查是否可以跳轉
|
||||
}
|
||||
|
||||
// --- 【新增方法】核心檢查跳轉邏輯 ---
|
||||
private void CheckAndLoadScene()
|
||||
{
|
||||
// 確保 ClientLastWordsSceneController.words 已經有值
|
||||
bool hasWords = !string.IsNullOrEmpty(ClientLastWordsSceneController.words);
|
||||
|
||||
if (isVideoFinished && isSignalReceived && hasWords)
|
||||
{
|
||||
Debug.Log("🎉 影片和訊號條件滿足,準備跳轉到下一場景...");
|
||||
StartCoroutine(LoadNextScene());
|
||||
}
|
||||
else if (isVideoFinished && !isSignalReceived)
|
||||
{
|
||||
// 影片已結束,等待訊號
|
||||
Debug.Log("影片已結束,正在等待玩家B訊號...");
|
||||
}
|
||||
else if (!isVideoFinished && isSignalReceived)
|
||||
{
|
||||
// 訊號已收到,等待影片結束
|
||||
Debug.Log("已收到玩家B訊號,正在等待影片播放完成...");
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator LoadNextScene()
|
||||
@ -61,4 +95,4 @@ public class ClientGameBackToRealSceneController : MonoBehaviour
|
||||
yield return new WaitForSeconds(0f);
|
||||
SceneManager.LoadScene("ClientLastWordsScene");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using System;
|
||||
|
||||
@ -81,10 +81,11 @@ public class ClientMessageHandler : MonoBehaviour
|
||||
ClientLastWordsSceneController.words = msg.payload;
|
||||
if (ClientGameBackToRealSceneController.Instance)
|
||||
{
|
||||
StartCoroutine( ClientGameBackToRealSceneController.Instance.LoadNextScene());
|
||||
// ✅ 將直接跳轉的程式碼,改為呼叫新的檢查函式
|
||||
ClientGameBackToRealSceneController.Instance.ReceiveSignalFromPlayerB();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
case "gameTalkingStart":
|
||||
|
||||
Loading…
Reference in New Issue
Block a user