31 lines
699 B
C#
31 lines
699 B
C#
using System;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class GameState
|
|
{
|
|
public string playerName;
|
|
public int level;
|
|
}
|
|
|
|
public class SaveManager : MonoBehaviour
|
|
{
|
|
public GameState gameState;
|
|
|
|
public void SaveGame()
|
|
{
|
|
var json = JsonUtility.ToJson(gameState);
|
|
File.WriteAllText(Application.persistentDataPath + "/gameState.json", json);
|
|
}
|
|
|
|
public void LoadGame()
|
|
{
|
|
var path = Application.persistentDataPath + "/gameState.json";
|
|
if (File.Exists(path))
|
|
{
|
|
var json = File.ReadAllText(path);
|
|
gameState = JsonUtility.FromJson<GameState>(json);
|
|
}
|
|
}
|
|
} |