Hello everybody, as the the title suggests, every time i load up the oldHighScore int in my code, it always returns 0, and i can’t for the life of me figure out why the heck it’s doing it. It’s probably obvious but after 2 hours of trying to find the problem i still can’t find out why. Does anybody know what the problem is?
CODE:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class SaveLoad : MonoBehaviour
{
public int newHighScore;
public int oldHighScore;
void Awake()
{
//DontDestroyOnLoad(GameObject);
}
void SaveGame()
{
Transform otherScript = GameObject.Find("gameSystems").transform;
newHighScore = otherScript.GetComponent<gameSystems>().score;
LoadGame();
if (newHighScore >= oldHighScore) ///if the new high score is higher than the old one
{
PlayerPrefs.SetInt("HighScoreInt", newHighScore); ///Sets HighScoreInt in playerprefs with the newHighScore int variable
}
}
void LoadGame()
{
oldHighScore = PlayerPrefs.GetInt("HighScoreInt"); /// Sets oldHighScore int with the HighScoreInt playerprefs thingamajigg
Debug.Log(oldHighScore);
}
}