Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

A number wont refresh depending on what the Playerpref is

Discussion in 'Scripting' started by byro210, Jun 5, 2014.

  1. byro210

    byro210

    Joined:
    Feb 18, 2014
    Posts:
    121
    Im trying to make it every time PlayerPrefs.("Current Health") Goes down so does the Number on

    static var DataCenter.CurrentHealth: which is what (PlayerPrefs.("Current Health") equals

    Ive got this code but whenever Current health goes down it doesn't refresh on the screen


    This is under Function GUI()
    Code (CSharp):
    1. {
    2.  
    3.     GUI.Label (new Rect (Screen.width/4.95f,Screen.height/1.40f, Screen.width/1.50f,Screen.height/10.2f),String.Format("{0}",DataCenter.CurrentHealth, textStyle));
    4.  
    5. }
    Help would be much appreciated

    Every second on the Map PlayerPrefs.("Current Health") Goes down by 1
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    PlayerPrefs are used to save data. It is not a good idea, in my opinion, to use it during play. You are better of using a variable inside your script.
     
  3. StaticNova

    StaticNova

    Joined:
    Feb 23, 2013
    Posts:
    60
    Are you updating DataCenter.CurrentHealth every time you do the PlayerPref? Paste the code for that.