Duplicate Question: http://answers.unity3d.com/questions/1037552/how-do-i-keep-object-destroyed-after-reloding-scen-1.html
how do i keep object destroyed after reloding scene ??
in my game I have free roam In which the character collect hidden objects. when I collect the object the score adds up and it is saved to playerprefs but the problem is that when I reload the scene the object that I collected appears again and the player can recollect it. so I am wondering what should I add to my code to keep the collected object from re-appearing. here is my code
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class iconcollect : MonoBehaviour {
public static int money; // The player's money.
public Text moneytext; // Reference to the Text component.
public string icon;
void Awake ()
{
// Set up the reference.
moneytext = GameObject.FindGameObjectWithTag("text").GetComponent<Text>();
money=(PlayerPrefs.GetInt("Money"));
icon = (PlayerPrefs.GetString ("icon"));
}
void Update ()
{
moneytext.text = money + "/100";
PlayerPrefs.SetInt ("Money", money);
}
void SetCountText ()
{
moneytext.text = "Count: " + money.ToString ();
if (money >= 12)
{
Application.LoadLevel("unlocklevel34");
}
}
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == " icon")
{
col.gameObject.SetActive(false);
money = money + 1;
}
}
}
Follow this Question
Related Questions
PlayerPrefs loading data inconsistently 1 Answer
A Little Help With Player Prefs 0 Answers
PlayerPrefs Not Saving When I Click the Button. 1 Answer
PlayerPrefs.enabled 0 Answers
Playerprefs not saving on Android but saving in unity run editor 2 Answers