_Ziens_

Unity - Auto Saving Script

Nov 5th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3.  
  4.     public class AutoSaving : MonoBehaviour
  5.     {
  6.         public float savingPeriod = 60f;
  7.         private World world;
  8.  
  9.         void Start ()
  10.         {
  11.             world = World.GetInstance ();  
  12.             StartCoroutine (OnSaveData ());
  13.         }
  14.  
  15.         IEnumerator OnSaveData ()
  16.         {
  17.             while (true) {
  18.                 yield return new WaitForSecondsRealtime (savingPeriod);
  19.                 Save ();
  20.             }
  21.         }
  22.  
  23.         public void Save ()
  24.         {
  25.             Debug.Log ("Saving...");
  26.             DataManager.SaveData (world);
  27.         }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment