based off this scirpt: using System.Collections; using System.Collections.Generic; using…
- User
based off this scirpt: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;
public class ScoreCounter : MonoBehaviour { public static int SCORE { get; set; } private Text uiText;
private void Start() { uiText = GetComponent<Text>(); LoadScore(); } private void Update() { uiText.text = SCORE.ToString("Score:#,0"); } public void AddScore(int scoreAmount) { SCORE += scoreAmount; SaveScore(); } public void ResetScore() { SCORE = 0; SaveScore(); } private void SaveScore() { PlayerPrefs.SetInt("Score", SCORE); } private void LoadScore() { SCORE = PlayerPrefs.GetInt("Score", 0); } private void OnEnable() { SceneManager.sceneLoaded += OnSceneLoaded; } private void OnDisable() { SceneManager.sceneLoaded -= OnSceneLoaded; } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.buildIndex == 0) // Check if the current scene is Level1 { ResetScore(); } }} write a new script that keeps track of the high score
- Assistant
Here's a new script that keeps track of the high score:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;
public class ScoreTracker : MonoBehaviour { public static int Score { get; set; } public static int HighScore { get; private set; }