Answer the question
In order to leave comments, you need to log in
Why is saving not working?
Debug message shows that update is running and everything is saved
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);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question