I am using PlayerPrefs to save collected coins on each level. In a differences game, when an item is found, player gets one coin and it is saved with PlayerPrefs. And that coin value is used to display in Level Selection screen. The problem is when i finished the level for the first time, it displayed collected coins in Level Selection screen, when i finished it another a couple of times, the value on the Level Selection screen, stayed the same, coins did not add up:
Here is my script where i save coins with PlayerPrefs:
if (result.collider.CompareTag("Images"))
{
Debug.Log("Hit");
result.collider.enabled = false;
tmpCircle = Instantiate(krug1);
tmpCircle.SetActive(true);
tmpCircle.transform.SetParent(canvas.transform, true);
tmpCircle.transform.position = new Vector3(result.point.x, result.point.y, result.point.z);
tmpCircle.transform.localScale = new Vector3(transform.localScale.x * 2f, transform.localScale.y * 2f, transform.localScale.z);
circle.Play("CircleAnim");
score += 1;
diff -= 1;
coins += 1;
score1.text = " " + score;
PlayerPrefs.SetInt("Coins", coins);
PlayerPrefs.Save();
item.Play();
}
And here is the script where i display the coins in LevelSelection Screen:
void Start()
{
coins.text = PlayerPrefs.GetInt("Coins", 0).ToString();
}