Код загрузчика на C#:
Синтаксис:
Используется csharp
public void LoadGame() // НЕ РАБОТАЕТ - СЦЕНА ВСЕГДА ПОСЛЕ ПРИСВАИВАНИЙ
{
if (File.Exists(Application.dataPath + "/Saved Games/Checkpoint.dgs"))
{
FileStream f = new FileStream(Application.dataPath + "/Saved Games/Checkpoint.dgs", FileMode.OpenOrCreate);
BinaryFormatter form = new BinaryFormatter();
try
{
int curl = (int)form.Deserialize(f);
Pos p = (Pos)form.Deserialize(f);
bool fr = (bool)form.Deserialize(f);
Debug.Log("Params: " + curl + " " + p.x + " " + p.y + " " + fr);
SceneManager.LoadScene(curl);
GameObject.Find("Hero").transform.position = new Vector2(p.x, p.y);
Debug.Log(p.x + " " + p.y);
Debug.Log("Deserialized face: " + fr);
GameObject.Find("Hero").GetComponent<characterController>().facingRight = fr;
}
catch (System.Exception e)
{
Debug.Log(e.Message);
}
finally
{
GameObject.Find("Hero").GetComponent<characterController>().health = 3;
GameObject.Find("Hero").GetComponent<BonusScript>().points = 0;
f.Close();
}
}
else
{
Debug.Log("Save data not found. Starting from the beginning of the level");
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
{
if (File.Exists(Application.dataPath + "/Saved Games/Checkpoint.dgs"))
{
FileStream f = new FileStream(Application.dataPath + "/Saved Games/Checkpoint.dgs", FileMode.OpenOrCreate);
BinaryFormatter form = new BinaryFormatter();
try
{
int curl = (int)form.Deserialize(f);
Pos p = (Pos)form.Deserialize(f);
bool fr = (bool)form.Deserialize(f);
Debug.Log("Params: " + curl + " " + p.x + " " + p.y + " " + fr);
SceneManager.LoadScene(curl);
GameObject.Find("Hero").transform.position = new Vector2(p.x, p.y);
Debug.Log(p.x + " " + p.y);
Debug.Log("Deserialized face: " + fr);
GameObject.Find("Hero").GetComponent<characterController>().facingRight = fr;
}
catch (System.Exception e)
{
Debug.Log(e.Message);
}
finally
{
GameObject.Find("Hero").GetComponent<characterController>().health = 3;
GameObject.Find("Hero").GetComponent<BonusScript>().points = 0;
f.Close();
}
}
else
{
Debug.Log("Save data not found. Starting from the beginning of the level");
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}