Y
Y
yraiv2020-05-14 15:10:07
Unity
yraiv, 2020-05-14 15:10:07

What is the best way to organize the save?

There is a script in which it is necessary to implement saving. What is the best way to do this, in the sense that if everything is stuffed into fixupdate, then the phone will be heavily loaded? Damage and Money change throughout the game, changes almost all the time.
here is the script with the method

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Balance : MonoBehaviour
{
    public int Money;
    public int Damage;
    public Text Money_Text;

    public void FixedUpdate()
    {
        Money_Text.text = "Коины: " + Money.ToString() ;
    }

    public void Save() // сохранение, которое не знаю в какой момент лучше всего вызывать 
    {
        string key = "Balance" ;
        PlayerPrefs.SetInt(key, this.Money);
        PlayerPrefs.SetInt(key, this.Damage);
        PlayerPrefs.Save();
    }

    public void Load()
    {
        string key = "Balance";
        if (PlayerPrefs.HasKey(key))
        {
            PlayerPrefs.SetInt(key, this.Money);
            PlayerPrefs.SetInt(key, this.Damage);
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
2
2CHEVSKII, 2020-05-14
@yraiv

What the hell is saving data every frame? Why can't they be saved after a certain period of time and when exiting the application?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question