I’m having some issues either saving with PlayerPrefs.SetVariable or loading with UnityEvent.Invoke. I’m trying to save both strings and bools in two separate classes. I’m not sure which since If one doesn’t work it cancels out the other. I’ve checked the console and it had no errors logged. As far as I can tell syntax wise both are correct. Is there something else I’m missing?
using UnityEngine;
using UnityEngine.Events;
public class UserSettingString : MonoBehaviour
{
public string stringText { get; set; }
public UserSettingEventString onSettingLoaded;
void OnEnable()
{
Load();
}
public void Load()
{
onSettingLoaded.Invoke(stringText = PlayerPrefs.GetString(name));
}
public void Save()
{
PlayerPrefs.SetString(name, stringText);
}
}
[System.Serializable]
public class UserSettingEventString : UnityEvent<string>
{
}
using UnityEngine;
using UnityEngine.Events;
public class UserSettingBool : MonoBehaviour
{
public bool boolToggle { get; set; }
public UserSettingEventbool onSettingLoaded;
void OnEnable()
{
Load();
}
public void Load()
{
onSettingLoaded.Invoke(boolToggle = PlayerPrefsX.GetBool(name));
}
public void Save()
{
PlayerPrefsX.SetBool(name, boolToggle);
}
}
[System.Serializable]
public class UserSettingEventbool : UnityEvent<bool>
{
}