I am going to give away the major components to the inventory system’s code, as a special thanks to the people in this forum who helped me put it together. Thanks for the advice and tips you gave to making it all possible!
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class PlayerPrefabScript : MonoBehaviour {
[System.Serializable]
public class Inventory {
public List<Item> items;
}
public Inventory inventory;
public Item itemInHand;
public Rect GUIArea = new Rect(0, 0, 0, 0);
void OnGUI () {
GUILayout.BeginArea(GUIArea);
GUILayout.BeginVertical();
foreach(Item item in inventory.items){
if(item != null){
if(GUILayout.Button(item.ItemID, GUILayout.Width(50), GUILayout.Height(50))){
itemInHand = item;
}
}
}
GUILayout.EndArea();
GUILayout.EndVertical();
}
void OnSaveInv () {
string SavedInv = JsonUtility.ToJson(inventory);
PlayerPrefs.SetString("SavedInv", SavedInv);
}
void OnLoadInv () {
string LoadedInv = PlayerPrefs.GetString("SavedInv");
Inventory LoadedItems = JsonUtility.FromJson<Inventory>(LoadedInv);
inventory = LoadedItems;
}
}
I will be updating the code later, as the above code is only part of the origional prototype.