If it matters, I have also used the following link to do this.
Anyway the codes is in C#, I have a Int variable called TrackerValue and I am trying to pass the TrackerValue into the Player Prefs.
It works when I put in
PlayerPrefs.SetInt(“trackername”,0);
But it does not work when I try
PlayerPrefs.SetInt(“trackername”,TrackerValue);
//I also did place public int TrackerValue=0 at the start.
So the question is, is it not possible to place the variable (TrackerValue)there and let Unity find out its value (0)?
Do I really have to follow the documentation where the value must be an integer?
//this is the reference.
static function SetInt (key : String, value : int) : void
///////////////////Code starts here
using UnityEngine;
using System.Collections;
using PlayerPrefs=PreviewLabs.PlayerPrefs;
public class Level1Script : MonoBehaviour {
public int TrackerValue;
public string CrackName=“crackvalue”;
// Use this for initialization
void Start () {
TrackerValue=0;
TrackerValue=PlayerPrefs.GetInt("trackername");
CrackName=PlayerPrefs.GetString("crackvalue");
Debug.Log(CrackName);
if (TrackerValue==0) {
TrackerValue++;
Saveaplayer();
}
}
// Update is called once per frame
//void Update () {
//}
public static void Saveaplayer() {
PlayerPrefs.SetInt("trackername",TrackerValue);
PlayerPrefs.SetString("crackname","the name of crack!");
PlayerPrefs.Flush();
}
}