Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

Problem with If statement and Collision!?

$
0
0
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.

Viewing all articles
Browse latest Browse all 1333

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>