PlayerPrefs guide

I am trying to understand how to use the player prefs with a simple method; Basically I want to instantiate a prefab (or play a sound) each time I report an achievement to Game Center - not every time I am reaching that particular level. So I use this in a function where

if (_level == 21)
{
shieldObject.renderer.material.mainTexture = shieldTexture[0]; //also change some textures to make it pretier
if (PlayerPrefs.GetInt("Player Achievement", 1))
 {
 GameCenter.ReportAchievement("achievement1");
 Debug.Log("Report achievement and instantiate the reward only once, not everytime we are on this level");
 }
   }

I am not sure when to set the value and when to read them. Following my artist logic I ended up with something really silly: when I reach the level I want I save the value. But this exactly where I want to read it too. Please help. Or laugh at me :slight_smile:

if (_level == 21) 
 {
 PlayerPrefs.SetInt("Player Achievement", 1);
 }

Finally got it. Works like a charm.

//check if field "PlayerAchievement" was already set [ 0 - unset, 1 - set] 
 if (PlayerPrefs.GetInt("PlayerAchievement1", 0) == 0)
 {
 //mark field "PlayerAchievement" to set
 PlayerPrefs.SetInt("PlayerAchievement1", 1);
 GameCenter.ReportAchievement("achievement1");
 Instantiate(myAchievement1Prefab);
 }