private void OnTriggerEnter(Collider other) { if (other.tag == "Player") { if (LevelHandler.GetCurrentCheckPointIndex() <= checkPointIndex) { LevelHandler.SetCurrentCheckPointIndex(checkPointIndex); GlobalMethods.SaveToSaveFile(); } if (checkPointIndex == 0) { GameObject.FindGameObjectWithTag("LEVEL_COLLECTOR").GetComponent <FaderEffect>().FadeIn(Color.black, 3); } } }
public static bool SaveToSaveFile() { Level level = LevelHandler.GetCurrentLevel(); if (level == null) { Debug.Log("Cannot save, you appear to not be in a level. (Did you add a levelcollector?)"); return(false); } if (!level.IsSavable) { Debug.Log("You cannot save in this level."); return(false); } SaveFile save = new SaveFile(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name, LevelHandler.GetCurrentCheckPointIndex()); BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, save); byte[] bytz = ms.ToArray(); FileStream file = File.Create(SAVEFILE_PATH); file.Write(bytz, 0, bytz.Length); file.Close(); Debug.Log("Saved successfully."); return(true); }