- Home /
Database and transferring variables
I've been looking around for this, and though I've found some pointers (like "DontDestroyOnLoad") it hasn't quite thrown me into the right direction. My situation is this: I'm having to make different scenes. In each scene are a few vendors with items in stock, and there is the player. Between each scene I need to save what items the vendors currently hold, I need to be able to add/remove items, edit the prices and some more things. Most importantly at the moment is saving what items and in what amounts. I also need to save the player's inventory, with what items the player holds and how much money.
How do I best go about this? I thought of having a universal "DatabaseScript" with a 'DontDestroyOnLoad' and between each scene, set and get players/NPCs.
Answer by Joshua · Mar 28, 2011 at 02:01 PM
You're absolutely right with your own suggestion. Have an empty game object with a script attached to it. Call this script gameManager or DatabaseScript or whatever. Add DontDestroyOnLoad to it and use it to store and access all variables that need saving.
Or, if you only have vendors with items in stock just add DontDestroyOnLoad to the vendorsStock script and make sure all the variables are static.
Good luck.
I tried this out, but it's not working so well. The problem lies in how to store all the data. Since I have an NPCScript that I attach to a gameObject in the scene, I am unsure of how to create a database with this kind of script (because I can't use script1 = new NPCScript and then assign variables)
Your answer
Follow this Question
Related Questions
How to properly transfer a scene via flashdrive to another computer? 1 Answer
how to transport a selection from scene to scene 1 Answer
transferring Sprite Mesh Animation frame value to another scene 1 Answer
World building based on "model scenes" 1 Answer
how do i make a script that records where a player was before entering another room 0 Answers