- Home /
Is there a way to disable something permanently in a script?
I'm setting up a shop for my game and need to use a buy button in front of the selection button but i don't know how to permanently disable the buy button after they purchase the skin i know its possible to disable the button but after i leave the scene or end the game it will just simply come back is there anyway to fix this any help is appreciated!
Answer by Chimer0s · Feb 19, 2019 at 01:48 AM
More information would be helpful. Without seeing how your code is set up and what exactly is happening I can suggest a couple of approaches.
The first and easiest, but least efficient and prone to tampering, method is to use PlayerPrefs to set a key for the item and assign a value for when it's purchased. Then reference that value at initialization to set the state of the buy button. Another more in-depth way to handle it would be to create a serializable class with the necessary information for the items in the shop that you store in a list in a binary-formatted saved file, which you then load the values of at initialization.
I assume you have some form of persistence already in place as you're letting them buy what sounds like permanent items. It's hard to give advice without knowing how it is that you're handling things like that. It might be a simple addition to a pre-existing system in your game.
Well i really just need to know how to delete an item permanently i really don't have any code except for a simple item.enabled = false; but it will always come back
Answer by reeper911 · Feb 19, 2019 at 03:28 AM
There is no way to edit your game scene at run time in a way that will still remain after the app finishes running. This prevents users from destroying their game scene through code.
If you need some sort or persistence then you are going to have to save this information and apply the state you want to display when the game starts again. You can either save it as a player pref or remotely in a database.
Your answer
Follow this Question
Related Questions
How do i stop infinite Jumping in the air 1 Answer
Unable to unhinge and hing a new object. 0 Answers
Is there a better way to tell when enemies are dead? 2 Answers
Calling a function via button from instance of prefab 1 Answer
A Unity Game Launcher? 3 Answers