I have a simple code for a player’s inventory. There is a script that determines the attributes of each item in the game:
using UnityEngine;
using System.Collections;
public class Item {
public string ItemName;
public string ItemDescription;
public int ItemDamage;
public GameObject ItemPrefab;
}
==============================================
The inventory is represented as :
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Inventory : MonoBehaviour {
public List<Item> PlayerInventory = new List<Item>();
public Item ItemInHand = null;
public Rect InvGUIArea = new Rect(0, 0, 0, 0);
void OnGUI () {
GUILayout.BeginArea(InvGUIArea);
GUILayout.BeginVertical();
foreach(Item item in PlayerInventory){
if(item != null){
if(GUILayout.Button(item.ItemName, GUILayout.Width(50), GUILayout.Height(50))){
ItemInHand = item;
}
}
}
GUILayout.EndArea();
GUILayout.EndVertical();
}
}
==================================================
I have not specified this in my previous threads, but I don’t want to just know how to save the inventory to the games online player database, but I want to be able to load it back as well.
The problem is, I don’t know how to do either of those. All I know is how to get the inventory to display the GUI and the item names in it, as well as allow the player to choose what item to hold. Unfortunately I don’t know how to make this whole thing persistent. The system should theoretically work by having an online database that stores each player’s info (username, passcode, gold in his inventory, items in his inventory, the amount of combat experience he has). I only know how to get the client and database to save and load the player’s username, password, experience, and gold. I don’t know how to get it to do the same for the player’s inventory. Note that the player’s amount of gold is NOT considered an actual item in the player’s inventory, but has a slot all for itself that displays the amount of gold the player has. But how am I supposed to make the inventory persistent. Thanks in advance.