- Home /
Destroy and Object and PlayerPrefs
Hi Guys ! I've created this simple script to unlock a character, but obviusly when i restart the game the destroyed button object is there :D
public void ToggleBallBlueButton()
{
GameManager.Instance.currency -= BallBlueCost;
GameManager.Instance.Save ();
BallBlueButton.SetActive (true);
Destroy (TgBallBlueButton);
}
There is a way ? Maybe with the PlayerPref to Destroy the button in all games ?
Answer by SergioSandiaz · Nov 02, 2016 at 05:44 AM
Yeah...with an improvised boolean, due the player prefs doesn´t support booleans, you need to use an integer variable with 1 as true and 0 as false, just check the value with an if and set the button off if necesary.
public GameObject Button;
void Start() {
if(PlayerPrefs.GetInt("Button") == 1){
Button.SetActive(true);
}else{
Button.SetActive(false);
}
}
Your answer
Follow this Question
Related Questions
Unity Character Selection + store 1 Answer
How to stop objects you picked up from reappearing when you go to another level and return 1 Answer
How do I get my endless runner high score,How do I make high score for an endless runner 1 Answer
My playerprefs wont save and load my int to TMPro text 1 Answer
Player prefs 0 Answers