- Home /
save scene and load using binary file
Hi, my game doesnt have main menu, just simply levels, when players opens the game i want to continue from last session scene(level) . how do i create binary file(or using playerprefs) . could you please help me how to save scene and load here in my game using binary file. here is my game code. please help me i am stuck here for last few days
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);
}
}
this is my gameManger script,
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));
}
}
Answer by MUG806 · Feb 20, 2021 at 01:39 PM
This is one of those things where there is no one solution. It depends what data you need to store for which objects. I'd look up some C# guides on Serialization, and saving objects to file.
i have used playerprefs to save for things like score. i just want to save scene number and load from that scene when player open the game , my game is hyper casual kind of game so there is no main menu just levels, when player open the game i just want to continue from last level(scene) he played .
Your answer
Follow this Question
Related Questions
Help please guys my game almost finished please 1 Answer
Script executing through walls 1 Answer
How do I make the enemy script/AI stop following me when It is in view of the player camera? 1 Answer
Is there another way of counting Scores (points) instead of Colliding (destroying) ?? 1 Answer
Why when using get; set; in one script i'm getting null in other script that use it ? 1 Answer