Im trying to get an if statement to work on collision...
void OnCollisionEnter(Collision other)
{
Score = GameObject.Find("Sphere").GetComponent().timerText.text;
PlayerPrefs.SetString("HighScore", Score);
Destroy(this.gameObject);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
this code works perfectly but if i were to include it in an if statement....:
void OnCollisionEnter(Collision other)
{
if (float.Parse(PlayerPrefs.GetString("HighScore")) < float.Parse(Score))
{
Score = GameObject.Find("Sphere").GetComponent().timerText.text;
PlayerPrefs.SetString("HighScore", Score);
Destroy(this.gameObject);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
else
{
Destroy(this.gameObject);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
That wont work at all, it acts as if though the entire void OnCollisionEnter doesnt exist!
So my problem is i need that second section of code to work but i simple cant and have no idea what im doing wrong so please help me!!
Thanks.
↧