- Home /
Best method to save states in/for a prefab
Hey so I've been experimenting with loading different small levels in same scene using prefabs. For now I am looking for simple solutions to, say, player collects a key and opens a door in a level (prefab) now he enters another level(prefab) which deletes the old one. With that done now when player goes back to old level the gate is locked again and collectible(key) is present again due to reloading asset from resources folder like a new one.
What I've been thinking that I could make a game controller that stores such information but I am not sure how it will work. Especially with the saving part since calling update function with long code seriously drips framerates in low-end phones. I would appreciate if someone with knowledge of same could shine some light on this ^^
Thanks
You could use PlayerPrefs
http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Construct the keys out of say level number and item_type. Then, whenever the player reloads a level, every Prefab could check it's state and instantiate configure itself that way
Here's what I thought. I can make a script which keeps track of all the items which needs to have their states saved. It may contain a global bool item[]. Then I can put something like this in start if(GlobalScript.item[key] == true) {Destroy(gameObject);}
So do you know a way by which collectible items can create their own keys and preserve them all the way until playerprefs data is deleted?