Search Unity

I am beginner and i cant get my highscores working

Discussion in 'Scripting' started by ReikoTennosaar, Oct 12, 2019.

  1. ReikoTennosaar

    ReikoTennosaar

    Joined:
    Oct 12, 2019
    Posts:
    5
    can someone please help me i really dont understand what is wrong.
    this is the script:

    using UnityEngine;
    using UnityEngine.UI;

    public class Score : MonoBehaviour
    {
    [Header("Please Drag Objects Here")]
    public Transform player;
    public Text currentScoreText;
    public Text highScoreText;

    private const string highScoreKey = "HighScore";

    [Header("Do not change values")]
    [SerializeField] private int highScore = 0;
    [SerializeField] private int currentScore = 0;

    private void start()
    {
    highScore = PlayerPrefs.GetInt(highScoreKey, 0);

    highScoreText.text = highScore.ToString();
    }

    private void Update()
    {
    currentScore = Mathf.RoundToInt(player.position.z);
    currentScoreText.text = currentScore.ToString();

    if (currentScore > highScore)
    {
    highScore = currentScore;
    highScoreText.text = highScore.ToString();

    PlayerPrefs.SetInt(highScoreKey, highScore);
    PlayerPrefs.Save();
    }
    }

    private void OnDisable()
    {

    PlayerPrefs.SetInt(highScoreKey, highScore);
    PlayerPrefs.Save();

    Debug.Log("I'm being Disabled! The high score is currently: " + highScore);
    }

    public void Reset()
    {
    PlayerPrefs.DeleteAll();
    highScoreText.text = "unset";
    }
    }
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Start not start. Unity MonoBehaviour messages are case-sensitive.