I want to save some PlayerPrefs and every Time i want to load the Float set it to 0

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

public class scr_Save : MonoBehaviour
{
public Text load;
// Start is called before the first frame update

public void Save(float counterNumber)
{
PlayerPrefs.SetFloat(“Variable”,counterNumber);
PlayerPrefs.Save();
}

public void Load()
{
load.text = PlayerPrefs.GetFloat(“Variable”) + " Sins";
}
}

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

Here’s an example of simple persistent loading/saving values using PlayerPrefs:

Useful for a relatively small number of simple values.

If you want to set the float to 0 whenever you load it, what exactly is the point in storing it in the first place?

2 Likes

I don´t want the 0 I always get the 0

Either look into the ready-made property aliases I listed in the pastebin link above (they work for sure), or else to debug your existing code, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.