Reading Player.prefs

I am trying to change the material of a medal - this is paired to Game Center Achievements; ANd I am using player prefs to show my custom medal (as opposed to the default GC achievement on top); Now - even if the player scores zero, on the end level it will see his last achieved medal. So when I am doing this:

	if (PlayerPrefs.GetInt("PlayerAchievement1", 1) == 1)
		{
			rank.renderer.material.mainTexture = RankTexture[0];
		}
	else if (PlayerPrefs.GetInt("PlayerAchievement2", 1) == 1)
		{
			rank.renderer.material.mainTexture = RankTexture[1];
		}

I get random results. What am I doing wrong?

The function PlayerPrefs.GetInt takes only one parameter: the key. You’re probably confusing it with setint, which takes two parameters: key and the value you want to set this particular key.

There is also another strange thing. You seem to look for two different keys, “PlayerAchievement1” and “PlayerAchievement2” but I imagine you want to check only one key “PlayerAchievement” and see if it has value of 1 or 2. Is that it? Try the code below, but beware that you also need to write the code that writes this playerprefs correctly!

if (PlayerPrefs.GetInt("PlayerAchievement") == 1)
       {
         rank.renderer.material.mainTexture = RankTexture[0];
       }
    else if (PlayerPrefs.GetInt("PlayerAchievement") == 2)
       {
         rank.renderer.material.mainTexture = RankTexture[1];
       }

edit: Actually, you might actually be looking for different achievements and checking their value as true (1) or false (2). In that case, try this code instead:

if (PlayerPrefs.GetInt("PlayerAchievement1") == 1)
       {
         rank.renderer.material.mainTexture = RankTexture[0];
       }
    else if (PlayerPrefs.GetInt("PlayerAchievement2") == 1)
       {
         rank.renderer.material.mainTexture = RankTexture[1];
       }