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);
}
}
↧