I have created an inventory system in js using dictionary definitions and guis but I cant figure out how to work this in with a crafting system, so if you know any good tutorials or over people that have a working crafting system plz link it …
I have put the script below for the inventory so you have an idea of what I am using, I have also placed an image below too show how I want the inventory to work.
//----------
var customSkin : GUISkin;
var Player : Transform;
var weaponHolder : Transform;
var playerCamera : Camera;
static var itemNum : int;
static var gotItem : boolean;
static var usingPick : boolean;
static var inInventory : boolean;
static var stackItem : boolean;
static var items = new System.Collections.Generic.Dictionary.<String,GameObject>();
//Create the dictionary full of a name and a GameObject associated with it.
static var curItem : System.Collections.Generic.KeyValuePair.<String, GameObject>;
static var curItemKey;
static var curWeapon : GameObject;
static var destroyWeapon : boolean;
//This will store the current item.
public var buttonHeight = 50;
public var width = 100;
function AddItemToInventory (item : GameObject) {
items.Add(item.name, item);
itemNum++;
Destroy(item);
}
function OnGUI() {
var curIndex = 0;
GUI.skin = customSkin;
GUI.BeginGroup (new Rect (400, 500, 400, 120));
for(var item : System.Collections.Generic.KeyValuePair.<String, GameObject> in items) {
//iterate through all the items in the dictionary.
var rect : Rect = new Rect((width+2) * curIndex, 0, width, buttonHeight);
var customStyle : GUIStyle;
var itemModel : GameObject;
var itemIndex : int;
var btnToggled : boolean;
var crafting : boolean;
var stacking = GameObject.Find(item.Key+("_model")).GetComponent(stacking);
itemIndex = curIndex;
GUI.skin = customSkin;
customStyle = customSkin.GetStyle("icon_"+item.Key);
btnToggled = GUI.Toggle(rect, btnToggled, curIndex+1+") x"+stacking.stackAmount, customStyle);
if(Event.current.Equals (Event.KeyboardEvent (curIndex+1+""))) {
curItem = item;
curItemKey = curItem.Key;
}
if (curItem.Key == item.Key){
itemModel = GameObject.Find(curItem.Key+"_model");
btnToggled = true;
GUI.Toggle(rect, btnToggled, curIndex+1+") x"+stacking.stackAmount, customStyle);
CreateWeapon(itemModel);
}else{
btnToggled = false;
GUI.Toggle(rect, btnToggled, curIndex+1+") x"+stacking.stackAmount, customStyle);
}
curIndex++;
}
GUI.EndGroup();
}
function CreateWeapon(weaponModel : GameObject){
if (curWeapon){
Destroy(curWeapon);
}
curWeapon = Instantiate(weaponModel,weaponHolder.position,weaponHolder.rotation);
curWeapon.transform.parent = weaponHolder.transform;
gotItem = true;
}
function Update(){
if(curWeapon){
var stacking = GameObject.Find(curItem.Key+("_model")).GetComponent(stacking);
}
if (itemNum < 0){
itemNum = 0;
}
if(gotItem && Input.GetKeyUp("q")){
if(stacking.stackAmount >1){
stacking.stackAmount--;
ObjNew(curWeapon);
}else{
stacking.stackAmount--;
ObjNew(curWeapon);
itemNum--;
RemoveItem(curItem);
destroyWeapon = true;
gotItem = false;
}
if (curWeapon && Input.GetMouseButton(0)){
swingWeapon(curWeapon);
}
}
if(destroyWeapon){
Destroy(curWeapon);
}
if(!curWeapon){
destroyWeapon = false;
}
}
function ObjNew(newItem:GameObject){
var object = Instantiate(newItem,weaponHolder.position,weaponHolder.rotation);
object.name = curItem.Key;
object.transform.parent = null;
object.AddComponent(Rigidbody);
object.AddComponent(BoxCollider);
object.AddComponent(Interaction);
}
function swingWeapon(weapon : GameObject){
weapon.animation.Play("use");
}
function RemoveItem (item : System.Collections.Generic.KeyValuePair.<String, GameObject>) {
yield WaitForEndOfFrame;
items.Remove(item.Key);
}
i realise it is a lot of code but the main bit us under the OnGui function, thanks in advance for the help and I realise I am asking a lot, so I really appreciate the help
[829-Crafting+Image.jpg|829]