If you only have to save player's position, you can use static variable
like below.
public static Vector3 playerPositionSaved = <your player posiiton>;
Save player's position data at OnDestroy()
on your scene management class or do it manually.
But this code only saves while application is running and dissapear when application ends.
To save player's data even application ends, you should save data as file with format(Like JSON, XML and so on) or use Unity's PlayerPrefs class.
JSON format example, you can declare class for your save data like this.
I usually use LitJson to generate json string and parse object from json string. But this time, i'll show you JsonUtility
from unity api.
public class SaveData
{
public static Vector3 playerPosition = Vector3.zero;
public static Vector3 playerNickName = Vector3
}
and save & load data like this
// Save
public void SaveData(SaveData saveData)
{
string savePath = Path.Combine(Application.persistantDatapath, "data.txt");
string jsonData = JsonUtility.ToJson(saveData);
File.WriteAllText(savePath,
}
// Load
public void LoadData()
{
string loadPath = Path.Combine(Application.persistantDatapath, "data.txt");
string jsonData = File.ReadAllText(loadPath);
SaveData loadedData = JsonUtility.FromJson<SaveData>(jsonData);
// this is saved player's position data
Vector3 playerSavedPosition = loadedData.playerPosition;
}
If you want to save all scene data, you should design well all of your class structures and save to file.
Or you may bye some related assets. There are several assets to save and load scene data automatically.