Как сбросить значение PlayerPrefs?
По задумке, игрок набирает очки ,но мне нужно чтобы их можно было сбрасывать,но когда функция Restart вызывается ничего не происходит(вызываю с помощью Button)
using UnityEngine;
using UnityEngine.UI;
public class ControllScores : MonoBehaviour
{
public Text Record;
public Text Score;
public Text PodcEtScore;
public int score;
public int record;
public float time;
private float timeStart;
void Start()
{
if (PlayerPrefs.HasKey("score"))
{
score = PlayerPrefs.GetInt("score");
}
timeStart = time;
}
void Update()
{
PlayerPrefs.SetInt("score", score);
time -= Time.deltaTime;
Record.text = "record: " + score;
Score.text = "score: " + record;
if (time <= 0)
{
record += 1;
time = timeStart;
}
if (record > score)
{
Record.text = "record: " + record;
score++;
}
else
{
Record.text = "record: " + score;
}
Invoke("PodcetScore", 0.2f);
}
void PodcetScore()
{
for (int i = 1; i < record; i++)
{
PodcEtScore.text = "Your score: " + record;
if (i < 10)
{
PodcEtScore.text = "Your score: " + record + " Bro, try again?...";
}
if (i >= 10)
{
PodcEtScore.text = "Your score: " + record + " Not bad...";
}
if (i >= 50)
{
PodcEtScore.text = "Your score: " + record + " Good";
}
if (i >= 100)
{
PodcEtScore.text = "Your score: " + record + " Very good!!!";
}
if (i >= 200)
{
PodcEtScore.text = "Your score: " + record + " Boy Boy nixyu TI Machina";
}
}
}
public void Restart()
{
PlayerPrefs.DeleteKey("score");
}
}
Источник: Stack Overflow на русском