Дебаг сообщения выдает, что update выполняется и всё сохраняется
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;
private float timeLeft;
public void Start()
{
Load();
}
public void FixedUpdate()
{
Money_Text.text = "Коины: " + Money.ToString() ;
}
public void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft < 0)
{
Save();
timeLeft = 5f;
Debug.Log("Вызван метод сохранения");
}
}
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);
}
}
}