hi …
i am trying to simple display scor player on the screen
using unity 5. UI
whats wrong on my code please help
#pragma strict
var my_score : String;
function Start () {
gameObject.GetComponent(UI.Text).text;
}
function Update () {
my_score = PlayerPrefs.GetInt("PlayerScore");
gameObject.GetComponent(UI.Text).text = my_score;
}
any help i will apreciate so much.
Hi,
Is Your script attached on object which have the Component Text? You got any error on Console?
Also, do not know how JS do cast (I use C #) but my_score is string and GetInt returns integer, perhaps the variable is getting null.
In addition, using GetComponent and PlayerPrefs on update can bring performance issues.
hi again … thanks . i solved in c#
I would like to know how it’s done, Java.
please , could you give me more info why performance decrease on update function using playerpref please
or any idea to use another method insted this ?
thanks again
PlayerPrefs often accesses the disk (even if that uses cache) and doing it 30 or 40 times per second It is not a good practice.
One of the possible solutions would be to create a reference to the Text in the script that you modify the score, for example:
// drag in inspector the GameObject that has the Text to this var
public Text textScore;
// and where you modify the score:
my_score += 10;
textScore.text = my_score.ToString();
...
Hope this help
change the score, only if the score change…
got it !!!