- Home /
Question by
Bananenwaffel123 · Jun 18, 2015 at 06:43 PM ·
levelloadcollectible-game-objects
Keeping objects destroyed during runtime of the game
Hello! I'm developing a game right now with diffrent scenes. The player starts in the Hub and changes to diffrent levels and always back to hub. I want the player to collect objects and keep them in the inventory. Im using this script:
void OnTriggerEnter(Collider col) {
InventoryHolder holder = col.GetComponent<InventoryHolder> ();
if (holder != null)
{
ItemStack addItemStack = new ItemStack(item, amount);
addItemStack = holder.AddStack(addItemStack);
if (addItemStack == null)
Destroy (this.gameObject);
else {
amount = addItemStack.itemCount;
}
}
}
}
But if the Player enters another scene the inventory is empty again and when I return to the first scene all the objects are there again an could be collected a second time. How could I prevent this? I want the objects to be destroyed during the whole runtime of the game. Many thanks in advance!!
Comment
Answer by Cherno · Jun 22, 2015 at 06:16 PM
You can start with looking into using PlayerPrefs for storing simple values. For saving more detailed data, you need to delve into Serialization / Deserialization.