void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "Enemy car") { if (ui.lives <= 0) { Destroy(col.gameObject); Destroy(gameObject); //if the saved score is less than the current score if (PlayerPrefs.GetInt("score") < ui.score) { PlayerPrefs.SetInt("score", ui.score); //save the new high score //PlayerPrefs.SetString("name", ui.name); //save the new high score player } } else { Destroy(col.gameObject); //if the saved score is less than the current score if (PlayerPrefs.GetInt("score") < ui.score) { PlayerPrefs.SetInt("score", ui.score); //save the new high score //PlayerPrefs.SetString("name", ui.name); //save the new high score player } ui.Collide(); am.crashSound.Play(); am.carSound.Stop(); //yield return new WaitForSeconds(1); am.carSound.Play(); //Instantiate(car, transform.position, transform.rotation); //reinstantiate the car } } if (col.gameObject.tag == "Coin") { Destroy(col.gameObject); am.coinSound.Play(); ui.score += 10; ui.coins += 1; ui.scoreText.text = "Score: " + ui.score; ui.coinsText.text = "Coins: " + ui.coins; } if (col.gameObject.tag == "Heart") { Destroy(col.gameObject); am.heartSound.Play(); ui.lives += 1; ui.score += 5; ui.livesText.text = "Lives: " + ui.lives; ui.scoreText.text = "Score: " + ui.score; } }