У нас вы можете посмотреть бесплатно Data Persistence Three Ways (Saving and Loading in Unity) или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Here's a copy of the final script if you need it. It takes only a couple changes to get this to look like the second type of persistence. For PlayerPrefs, there isn't a whole lot of typing, so I left that example out of the description, but it is in the beginning of the video. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; public class ScoreIncrease : MonoBehaviour { public Text scoreText; public int score; public static ScoreIncrease si; private void Awake() { if (si == null) si = this; else Destroy(this); DontDestroyOnLoad(this.gameObject); } void Update() { if (Input.GetKeyDown(KeyCode.Space)) { score++; scoreText.text = "Score: " + score; } if (Input.GetKeyDown(KeyCode.A)) { SceneManager.LoadScene(1); } } public void Save() { score++; scoreText.text = "Score: " + score; BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/scoreContainer.dat", FileMode.Create); ScoreContainer sc = new ScoreContainer(); sc.score = score; bf.Serialize(file, sc); file.Close(); } public void LoadScore() { if (File.Exists(Application.persistentDataPath + "/scoreContainer.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/scoreContainer.dat", FileMode.Open); ScoreContainer sc = (ScoreContainer)bf.Deserialize(file); file.Close(); score = sc.score; scoreText.text = "Score: " + score; } } } [Serializable] public class ScoreContainer { public int score; }