It's
UnityEngine.SceneManagement.SceneManager.LoadScene("Gameplay");
是的,它“立即”完成——也就是说s同步地。
换句话说,它“停”在该行代码处,等待加载整个场景(即使需要几秒钟),然后新场景开始。
不要使用您在问题中提到的旧命令。
请注意,Unity 还能够执行以下操作a同步加载..它“在后台缓慢加载新场景”。
However:我鼓励您只使用普通的“LoadScene”。重要的是可靠性和简单性。用户只需不介意如果机器在关卡加载时“停止”几秒钟。
(每次我在电视上单击“Netflix”时,电视都需要一些时间才能执行此操作。没人关心 - 这很正常。)
但如果您确实想在后台加载,请按以下方法...
public void LaunchGameRunWith(string levelCode, int stars, int diamonds)
{
.. analytics
StartCoroutine(_game( levelCode, superBombs, hearts));
}
private IEnumerator _game(string levelFileName, int stars, int diamonds)
{
// first, add some fake delay so it looks impressive on
// ordinary modern machines made after 1960
yield return new WaitForSeconds(1.5f);
AsyncOperation ao;
ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("Gameplay");
// here's exactly how you wait for it to load:
while (!ao.isDone)
{
Debug.Log("loading " +ao.progress.ToString("n2"));
yield return null;
}
// here's a confusing issue. in the new scene you have to have
// some sort of script that controls things, perhaps "NewLap"
NewLap newLap = Object.FindObjectOfType< NewLap >();
Gameplay gameplay = Object.FindObjectOfType<Gameplay>();
// this is precisely how you conceptually pass info from
// say your "main menu scene" to "actual gameplay"...
newLap.StarLevel = stars;
newLap.DiamondTime = diamonds;
newLap.ActuallyBeginRunWithLevel(levelFileName);
}
注意:该脚本回答了当玩家点击“进入实际游戏场景”时如何“从主菜单”传递信息的问题。