- Home /
Question by
Kajal · Oct 04, 2014 at 01:45 PM ·
why I am not getting highest value in my highscore textfield?
I am trying somethings like this....
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
float highscore = 0.0f,score = 0.0f;
OffSet2 OffSet;
void Start () {
OffSet = GameObject.FindWithTag("MainCamera").GetComponent<OffSet2>();
score = OffSet2.step;
if(PlayerPrefs.GetFloat("highscore",0.0f) < score)
{
PlayerPrefs.SetFloat("highscore", score);
}
}
void OnGUI()
{
GUI.Label(new Rect(300,210,70,20),"Score :");
GUI.TextField(new Rect(400,210, 70, 20), score.ToString());
GUI.Label(new Rect(300,240,80,20)," High Score :");
GUI.TextField(new Rect(400,260, 80, 20), highscore.ToString());
}
}
But I am getting zero value in my Highscore Textfield..
thanks!! kajal
Comment
Best Answer
Answer by fafase · Oct 04, 2014 at 01:49 PM
You are setting the value in PlayerPrefs but I cant see where you update the highscore variable of the script.
I guess that should fix it:
if(PlayerPrefs.GetFloat("highscore",0.0f) < score)
{
PlayerPrefs.SetFloat("highscore", score);
highscore = score;
}
Still you are doing that in the Start so both values will be 0 and that won't do much.
This should be called at some point later in the game for the values to be updated.
Your answer
Follow this Question
Related Questions
camera does not follow player after build 0 Answers
How to control photon server while getting disconnect automatic 0 Answers
Future Augment 1 Answer
Program control not entering onTriggerEnter() 1 Answer
Cloud recognition in Vuforia 0 Answers