Quantcast
Channel: Latest Questions by RoboticSarcasm
Viewing all articles
Browse latest Browse all 40

Saved int always returns 0 when loaded [C#]

$
0
0
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().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); } }

Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>