I have an if statment, line 47, and it’s not working with my playerperfs key of highscore.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameManager : MonoBehaviour {
public bool inPlay;
public float levelTimeSeconds;
float totalTime;
float finishTime;
public Text highscoreText;
public Text timeText;
public Text finishText;
void Start(){
totalTime = levelTimeSeconds;
highscoreText.text = ("Highscore: " + PlayerPrefs.GetFloat("Highscore"));
}
void Update(){
if (inPlay) {
levelTimeSeconds -= Time.deltaTime;
}
if (levelTimeSeconds < 0) {
//TimeUp Script
}
timeText.text = ("Time: ") + (levelTimeSeconds).ToString ("##");
}
void OnTriggerEnter(Collider collision){
if (collision.gameObject.tag == "finish") {
inPlay = false;
finishTime = (totalTime - levelTimeSeconds);
finishText.text = ("You took " + finishTime.ToString ("##") + (" seconds."));
if (PlayerPrefs.GetFloat("Highscore") == 0){
PlayerPrefs.SetFloat ("Highscore", finishTime);
}
if(finishText < PlayerPrefs.GetFloat("Highscore")){
PlayerPrefs.SetFloat ("Highscore", finishTime);
}
}
}
void OnTriggerExit(Collider exit){
if (exit.gameObject.tag == "start") {
inPlay = true;
}
}
}