title: Unity2D: PlayerPrefs.HasKey
body: <p>I'm using playerprefs to save data through out scenes. Although I'm having troubles with saving this data when the application is closed. You see I have a IAP shop that gives the player a boomerang when they purchase one, the boomerang effect (done inside my script) is activated through a button. My problem is, is that playerprefs.haskey isn't saving my boomerang effect when I close the game and then reopening it. Although it does save my boomerang effect when through scenes. This is my script:</p>
  
  <pre><code>public bool forceActive = false; 
  public GameObject BoomerangOn, BoomerangOff;
  public static int buttonCount = 0;
  static int timesActivated =  0;
  
  void Start()
  {
      if (PlayerPrefs.HasKey ("boomerangbutton")) {
          buttonCount = PlayerPrefs.GetInt ("boomerangbutton");
          BoomerangEffect();
      }
  }
  
  void Update()
  {
      PlayerPrefs.SetInt("boomerangbutton", buttonCount);
  }
  
  public void Activated ()
  {
      if(timesActivated &lt; BoomeerangText.score)
      {
          timesActivated++;
          StartCoroutine(BoomerangEffect());
      }
  }
  
  IEnumerator BoomerangEffect()
  {
  
          BoomerangOn.SetActive (true);
          yield return new WaitForSeconds (10.0f);
          BoomerangOn.SetActive (false);
          BoomerangOff.SetActive (true);
          yield return new WaitForSeconds (1f);
          BoomerangOff.SetActive (false);
          forceActive = false;
      }
  </code></pre>
  
  <p><strong>Second Edit</strong></p>
  
  <p>Okay I research a bit and linked up boomerang effect script with my boomerang text script. When the user purchase a boomerang from my IAP store, they will get 5 boomerangs, once clicked on, the boomerang text int will go down (like 5, 4, 3, 2 and 1 ) and so will my buttoncount int(that is why the timesactivaed is needed). However I change the Activated function to:</p>
  
  <pre><code> public void Activated ()
     {
      if (timesActivated &lt; BoomeerangText.score) {
              timesActivated++;
              StartCoroutine (BoomerangEffect ());
      }
  }
  </code></pre>
  
  <p>So far it works regarding activating my boomerang effect when the application is closed, but when it gets to the last int (1) nothing happens, my effect doesn't takes place, so far this is my only problem. 
  Above is an updated version of what my code looks like now. And below is my Boomerang text script: </p>
  
  <pre><code>public static int score = 0;        // The player's score.
  public static int click = 1;
  public GameObject button;
  
  
  Text text;                      // Reference to the Text component.
  
  // Use this for initialization
  void Start()
  {
      if (PlayerPrefs.HasKey ("boomerangTextInt")) {
          score = PlayerPrefs.GetInt("boomerangTextInt");
      }
  } 
  
  void Awake()
  {
      text = GetComponent&lt;Text&gt;(); 
  }
  
  public void Update()
  {
      SetScoreText();
      PlayerPrefs.SetInt("boomerangTextInt", score);
  }
  
  void SetScoreText()
  {
      text.text = " " + score;
      if (score &lt;= 0)
      {
          text.text = "None";
          button.GetComponent&lt;Button&gt;().interactable = false;
      }
      else if (score &gt;= 1)
      {
          button.GetComponent&lt;Button&gt;().interactable = true;
      }  
      // Set the displayed text to be the word "Score" followed by the score value.
  }
  public void MinusBoomerangText()
  {
      score -= click;
      text.text = " " + score;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And in my purchasing script I have this:</p>
  
  <pre><code>        public int scoreValue = 5;
  
          if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_5_BOOMERANG, StringComparison.Ordinal))
          {
          BoomerangEffect.buttonCount += 5;
              BoomerangText.score += scoreValue;
              Debug.Log("Purchase successfull");
          }
  </code></pre>
  
  <p>Thank you.:)</p>