Yesterday it work Fine But, when I open today this error popup.
“NullReferenceException: Object reference not set to an instance of an object
StoredPref.retrieveData () (at Assets/StoredPref.cs:18)”
here’s the script:
public class StoredPref : MonoBehaviour {
VariablesTemp variablesTemp;
void Start()
{
variablesTemp = GetComponent<VariablesTemp>();
}
public void retrieveData()
{
if (PlayerPrefs.HasKey("ShopCash"))
{
Debug.Log(PlayerPrefs.GetFloat("ShopCash"));
Debug.Log(PlayerPrefs.GetFloat("TotalCash"));
Debug.Log(PlayerPrefs.GetFloat("PersonalCash"));
variablesTemp.ShopCash = PlayerPrefs.GetFloat("ShopCash");
variablesTemp.TotalCash = PlayerPrefs.GetFloat("TotalCash");
variablesTemp.PersonalCash = PlayerPrefs.GetFloat("PersonalCash");
}
else {
PlayerPrefs.SetFloat("ShopCash", 0);
PlayerPrefs.SetFloat("TotalCash", 0);
PlayerPrefs.SetFloat("PersonalCash", 0);
}
}
Output is : 5 50 5
VariablesTemp script is attached to the same gameobject where StorePref is in.
and here VariablesTemp Script:
public class VariablesTemp : MonoBehaviour {
public float TotalCash;
public float ShopCash;
public float PersonalCash;
}
is it PlayerPrefs or Variables that is giving me this error?