【发布时间】:2021-05-22 03:34:29
【问题描述】:
我的游戏没有主菜单,只有关卡,当玩家打开游戏时,我想从上一个会话场景(关卡)继续。我如何创建二进制文件(或使用 playerprefs)。你能帮我如何使用二进制文件保存场景并在我的游戏中加载吗?这是我的游戏代码。请帮助我,我最近几天被困在这里
public class PlatformBuild : MonoBehaviour
{
void Awake()
{
LoadLevel();
}
public void LoadLevel()
{
float spawnPosZ = -42.86f;
for (int i = 0; i < PlatformsSize; i++)
{
GameObject platform = Instantiate(RandomPlatform, transform);
platform.transform.localPosition = new Vector3(0, 0, spawnPosZ);
platform.transform.localEulerAngles = new Vector3(0, 0, UnityEngine.Random.Range(0, 360));
spawnedPlatforms.Add(platform);
}
GameObject finalPlatformInstance = Instantiate(finalPlatform, transform);
finalPlatformInstance.transform.localPosition = new Vector3(0, 0, spawnPosZ);
}
}
这是我的游戏管理器脚本,
public class GameManager : MonoBehaviour
{
public void NextLevel()
{
LevelCompletedMenu.SetActive(false); StartCoroutine(LoadFade(SceneManager.GetActiveScene().buildIndex + 1));
}
public void RestartLevel()
{
score = 0;
StartCoroutine(LoadReStart());
GameOver.SetActive(false);
StartCoroutine(LoadFade(SceneManager.GetActiveScene().buildIndex));
}
}
【问题讨论】:
-
but it didnt work到底是什么意思?得到任何错误?您确定调用了相应的方法吗? -
playerprefs 保存关卡编号但场景未加载
-
你应该 Debug your code with breakpoints 看看有什么不符合你的预期