High Score Saving and Displaying on another scene
Hi! so i've been struggling with this project for a while, I have a score system on the game scene like this:
public class GameDirector : MonoBehaviour { GameObject Text; GameObject Countdown; bool trigger; bool timed = false; string score; string count; float time = 0; bool countimed = true; float countime = 4;
// Use this for initialization
void Start () {
this.Text = GameObject.Find("Realtime");
this.Countdown = GameObject.Find("Countdown");
StartCoroutine(WaitThreeSeconds());
}
IEnumerator WaitThreeSeconds(){
trigger = false;
yield return new WaitForSeconds(3);
trigger = true;
}
void Update()
{
float counter = countime -= Time.deltaTime;
float counter1 = counter - 1;
string timer = counter1.ToString("F0");
if (trigger == true)
{
timed = !timed;
}
if (timed){
float length = time += Time.deltaTime * 42;
PlayerPrefs.SetFloat("ThisScore", length);
if (length >= 0){
score = Text.GetComponent<Text>().text = length.ToString("F2");
}
}
and then I have a score display on the game over scene that comes after like this:
using UnityEngine; using UnityEngine.UI;
public class Score : MonoBehaviour { GameObject score;
// Use this for initialization
void Start () {
this.score = GameObject.Find("NewtonsApple");
}
private void Update()
{
float length = PlayerPrefs.GetFloat("ThisScore");
score.GetComponent<Text>().text = length.ToString("F2");
}
}
How can i alter this code so I have a high score displaying on the game over scene as well? I'm relatively new to unity so after all the work i still cannot seem to figure it out! It would be awesome if someone could help me. ("NewtonsApple, Realtime" is an UI Text)
Did you solve this?? I am struggling with this right now :/
Your answer
Follow this Question
Related Questions
Code check. Is my Highscore saving code OK? 3 Answers
Hey i am trying to add a time score system and time high score system need help. 0 Answers
displaying high score 1 Answer
High Score Save iOS 0 Answers