x


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 :)

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

asked Jul 15 '12 at 03:20 PM

Airship Games gravatar image

Airship Games
257 49 69 86

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
 }
more ▼

answered Jul 21 '12 at 08:50 AM

Airship Games gravatar image

Airship Games
257 49 69 86

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2

asked: Jul 15 '12 at 03:20 PM

Seen: 241 times

Last Updated: Jul 21 '12 at 08:50 AM