Y
Y
yraiv2020-05-14 16:20:51
Unity
yraiv, 2020-05-14 16:20:51

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

1 answer(s)
F
freeExec, 2020-05-14
@yraiv

What are you Loaddoing SetInt? I see no difference fromSave

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question