Crafting system

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]

This isn’t a very tough problem in algorithmic terms, but it is fairly involved. I think it would be best to implement the solution in stages, so that you can ask specific questions about those, should you run into trouble. Otherwise, it’s going to be too big a fish to swallow, so to speak. Try meeting the following criteria, one at a time.

You need an inventory of items.

You need to be able to display the inventory.

The player needs to be able to select an item. The selected item needs to be marked as such.

You need a recipe for a crafted item. It needs to specify the components and the result. There may be a varying number of components, but only one result. You’re going to have to decide if there’s an absolute maximum number of potential components in a recipe (if there is, then the implementation is going to be easier).

You need a collection of recipes. You’re going to be searching it a lot, and you want to do that efficiently, so this piece is going to require a bit of thought.

You need a crafting table, which is basically a set of slots.

You need to be able to display the table (i.e. all of its slots).

When an item from the inventory is selected, it needs to appear on the table, in the first free slot (which you need to find automatically, unless you want to create a drag and drop interface for the player to do it manually).

The items on the table need to be marked as such (eg. displayed “on the table”).

The player needs to be able to unselect the item. When that happens, the item needs to disappear from the table and the slot needs to be made free.

Every time the contents of the table change, you need to search the recipe list against the contents, in order to find all matching recipes. There are several way to do this, some of which are smarter than others, but simply going through the entire collection and checking each entry against the contents of the table will do at first.

You need to be able to display the matching recipes.

The player needs to be able to pick one recipe.

When player picks a recipe, the items that match recipe’s components need to be removed from the inventory and from the table. The resulting item needs to be put in the inventory (note that this affects the following: the items being selected, the contents of the table, and, by extension, the list of matching recipes).

why mine when i create it on c# script it has alot of errors : like this →

already change the using System.Collections to generic;
it is still wrong.
will some help me?

using UnityEngine;
using System.Collections.Generic;

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.();
//Create the dictionary full of a name and a GameObject associated with it.
static var curItem : System.Collections.Generic.KeyValuePair.;
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.) {
yield WaitForEndOfFrame;
items.Remove(item.Key);
}