Hi, in my game I’m trying to save high score but it saves even tho the high score is lower than the High Score why is it doing that? here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SetHighScore : MonoBehaviour
{
private PlayerMovement PlayerMovement;
public Button button;
public float HighScore;
private float oldScore = PlayerPrefs.GetFloat("HighScore");
private void Start()
{
HighScore = PlayerMovement.chubbyScore;
GameObject Player = GameObject.FindWithTag("Player");
PlayerMovement playerMovement = Player.GetComponent<PlayerMovement>();
Button btn = button.GetComponent<Button>();
btn.onClick.AddListener(SaveHighScore);
}
private void SaveHighScore()
{
//check if score is higher than highscore
if (oldScore < HighScore)
{
HighScore = PlayerMovement.chubbyScore;
PlayerPrefs.SetFloat("HighScore", HighScore);
}
}
}