Hey, I’m trying to get PlayerPrefs to work on iOS and it currently isn’t working, could one of you have a look at my code below for me? I’m hoping i’m not missing something obvious but please tell me if I am, I’m just trying to learn this. If I can get it to work with just saving the attempts I’d be looking at moving onto getting it to add lives in the background but getting it to just save is my goal for now.
Thanks to anyone who can help.
public class AttemptsController : MonoBehaviour {
public Text attemptText;
DateTime oldTime;
DateTime currentTime;
private float StartTime;
public int timeToAdd;
public static int attempts;
private int TimeDifference;
int minutes;
int attemptsGiven;
private GUIStyle guiStyle = new GUIStyle();
void Awake()
{
DontDestroyOnLoad(transform.gameObject);
PlayerPrefs.GetInt("RemainingAttempts");
}
void Start ()
{
attempts = 0;
minutes = 0;
oldTime = System.DateTime.Now;
PlayerPrefs.GetInt("RemainingAttempts");
}
void Update ()
{
currentTime = System.DateTime.Now;
minutes = currentTime.Minute - oldTime.Minute;
TimeDifference = (int)((Time.timeSinceLevelLoad+timeToAdd) - StartTime);
if (TimeDifference >= 10)
{
timeToAdd = 0;
StartTime = Time.timeSinceLevelLoad;
if(attempts < 5)
{
attempts += 1;
}
}
}
public void OnGUI()
{
guiStyle.normal.textColor = Color.white;
guiStyle.fontSize = 30;
GUI.Label (new Rect (900, 300, 400, 100), attempts.ToString(),guiStyle);
}
void OnApplicationQuit()
{
PlayerPrefs.SetInt("RemainingAttempts", attempts);
}
}