Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Highscore not working

$
0
0
Making a game where every enemy killed gives a specific number, and I want to make a highscore Please help Score Script: public class ScoreScript : MonoBehaviour { [SerializeField] Text score; [SerializeField] Text Highscore; int HighScore = 0; public static int yourScore = 0; void Start() { Highscore.text = PlayerPrefs.GetInt("Highscore", 0).ToString(); } void Update() { Highscore.text = "Highscore " + HighScore; score.text = "Score " + yourScore; } public void EnemyHit() { if (yourScore > HighScore) PlayerPrefs.SetInt("HighScore", yourScore); Highscore.text = yourScore.ToString(); } public void IncreaseScore() { } } The enemy script which I attach the score: public class CubeletEnemy : MonoBehaviour { public int health = 100; public void TakeDamage(int damage) { health -= damage; if (health <= 0) { Die(); } } void Die() { Destroy(gameObject); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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