Question by
z0code0z · Jun 30, 2018 at 09:11 AM ·
collisionplayerprefsif statementvoid
Problem with If statement and Collision!?
Im trying to get an if statement to work on collision...
void OnCollisionEnter(Collision other)
{
Score = GameObject.Find("Sphere").GetComponent<TimerFireball>().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<TimerFireball>().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.
Comment
Do you get any errors?
Have you tried logging the two scores just before the if statement?
Your answer
Follow this Question
Related Questions
CS1525 Unexpected symbol '=', HELP!!! 2 Answers
Decrease Lives on collision 1 Answer
In void bool dont changing 1 Answer
Cannot implicitly convert type `void' to `bool' 1 Answer
Why does it display an error? 2 Answers