[英]save and load scene unity
我的游戏没有主菜单,只有关卡,当玩家打开游戏时,我想从上一个 session 场景(关卡)继续。 我如何创建二进制文件(或使用 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));
}
}
包含单个int
可以通过多种方式很好地存储。 如果您不希望人们能够进行一些文件侦查以更改他们所在的场景,则可以使用二进制文件,尽管简单地创建一个包含数字的文本文件会更容易。 我敢肯定PlayerPrefs
也可以工作。 就实际操作而言,这三个都是非常常见的任务,因此可能通过一些谷歌搜索,您可以找到大量关于它的教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.