For some reason my if statement is not working as it should.
private void Update()
{
i = Mathf.Round(transform.position.z + 14.96f);
tm.text = i.ToString() + " m";
}
public void HighScore()
{
GameObject HighScoreObj = Instantiate(highScore);
HighScoreObj.transform.position = new Vector3(transform.position.x + 4.4f,transform.position.y + 3.2f,transform.position.z - 0.12f);
if (i > PlayerPrefs.GetFloat("HighScore"))
{
highScore.GetComponent<TextMeshPro>().SetText("New Record!");
PlayerPrefs.SetFloat("HighScore", i);
PlayerPrefs.Save();
}
if (i < PlayerPrefs.GetFloat("HighScore"))
{
highScore.GetComponent<TextMeshPro>().SetText("Record " + PlayerPrefs.GetFloat("HighScore") + "m");
}
Time.timeScale = 0;
}
It is setting the text of what it should have been in the last playmode. For example, if i = 10
and PlayerPrefs.Float = 5
when HighScore() is called the text changes to "Record "
. And if I enter another playmode test, it will make the text say "New Record!"
even if i
is less then the playerpref float. So summed up, it pretty much returns the if statement
of the last playmode test. Is this a glitch with Unity or what? It is very frustrating because it is such basic code and yet I have not got it working, so any help would be very appreciated!