Hello I’ve managed to get my PlayerPrefs.GetInt(); To successfully transfer to my 2nd scene, but what appears to be the problem on the 2nd level is that the score would be set default to 0 and would only got back to it’s playerpref int once another scorepoint is picked up. I’m not sure what I’m doing wrong or what I have missed.(Written in C#)
public Text CountText;
public AudioClip Pickup;
private int count ;
// Use this for initialization
void Start ()
{
count = 0;
PlayerPrefs.SetInt ("count", count);
PlayerPrefs.Save ();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{ //anything with the tag "pick me up" disappers on contact with the player
if (other.gameObject.CompareTag ("PICKMEUP")) {
other.gameObject.SetActive (false);
count = PlayerPrefs.GetInt("count") + 1;
SetCountText();
float volume = 0.2f;
AudioSource.PlayClipAtPoint(Pickup, transform.position, volume);
PlayerPrefs.SetInt("count", count);
PlayerPrefs.Save();
}
}
void SetCountText ()
{
CountText.text = "X " + count.ToString ();
}
On my second level I have a script that is almost a duplicate to the one above, but with slight changes.
void Start () {
if(PlayerPrefs.HasKey("Test"))
{
count = PlayerPrefs.GetInt("count");
SetCountText ();
}
}
After this second image I would pick up a coin and get the correct Int, but how can I fix it not displaying the right Int at the start of the second level?