Unity:场景在真实设备上重叠
Unity: Scene overlapping on real device
我有一个 2D 游戏,我在菜单场景中的“开始”按钮上使用以下代码,并在我的玩家在游戏场景中死亡后在“重新启动”按钮上使用以下代码。仅当我使用 Build & 运行 Unity 设置在真实设备上玩游戏时才会出现此问题。我有两个按钮可以移动我的播放器,按下它们几次后,移动会滞后,菜单场景会在播放时重叠在我的游戏场景上。每次游戏开始时都会发生。更直接的说。我正在玩游戏,突然黑色背景和两个大的“开始”和“设置”按钮在我玩游戏的过程中闪烁并滞后于我的控件,然后它们消失了。有谁知道这个问题可能来自哪里?
public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
}
很奇怪,这不应该发生。
但是,请尝试将 LoadSceneAsync
与此代码一起使用,看看错误是否仍然存在:
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class ScenesManager : MonoBehaviour {
IEnumerator loadScene;
public float loadingProgress;
public void LoadScene(string levelName) {
loadScene = AsyncLoad(levelName);
StartCoroutine(loadScene);
}
private IEnumerator AsyncLoad(string levelName) {
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Single);
asyncLoad.allowSceneActivation = false;
while (!asyncLoad.isDone) {
loadingProgress = Mathf.Clamp01(asyncLoad.progress);
asyncLoad.allowSceneActivation = false;
if (asyncLoad.progress == 0.9f) {
asyncLoad.allowSceneActivation = true;
}
yield return null;
}
}
}
我有一个 2D 游戏,我在菜单场景中的“开始”按钮上使用以下代码,并在我的玩家在游戏场景中死亡后在“重新启动”按钮上使用以下代码。仅当我使用 Build & 运行 Unity 设置在真实设备上玩游戏时才会出现此问题。我有两个按钮可以移动我的播放器,按下它们几次后,移动会滞后,菜单场景会在播放时重叠在我的游戏场景上。每次游戏开始时都会发生。更直接的说。我正在玩游戏,突然黑色背景和两个大的“开始”和“设置”按钮在我玩游戏的过程中闪烁并滞后于我的控件,然后它们消失了。有谁知道这个问题可能来自哪里?
public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
}
很奇怪,这不应该发生。
但是,请尝试将 LoadSceneAsync
与此代码一起使用,看看错误是否仍然存在:
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class ScenesManager : MonoBehaviour {
IEnumerator loadScene;
public float loadingProgress;
public void LoadScene(string levelName) {
loadScene = AsyncLoad(levelName);
StartCoroutine(loadScene);
}
private IEnumerator AsyncLoad(string levelName) {
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Single);
asyncLoad.allowSceneActivation = false;
while (!asyncLoad.isDone) {
loadingProgress = Mathf.Clamp01(asyncLoad.progress);
asyncLoad.allowSceneActivation = false;
if (asyncLoad.progress == 0.9f) {
asyncLoad.allowSceneActivation = true;
}
yield return null;
}
}
}