How do i create a crafting system like this video?

https://www.youtube.com/watch?v=TJqPp_2N6oY

Hi! Can you show example of (SIMPLE CRAFTING SCRIPT) like in the video.
Im a Java script coder but i cant create a script like crafting.

var ItemA : GameObject;
var ItemB : GameObject;
 
function Update() {
 
//The way ItemA and ItemB craft.
 
if(ItemA.name == "wood" && ItemB.name == "nails")
 
{
 
print("we've made a chest");
 
  }
}

How do i create the Crafting Fuction?
Means when Mouse click on it and it craft something?
it shows a GUI when click on it.

// Mess around with these values to specify the width, height, And position
 
var X : int = 15; // X position
var Y : int = 15; // Y position
var H : int = 200; // button height
var W : int = 100; // button width
 
//This Function allows the GUI
function OnGUI(){
// This line of code draws the button
GUI.Button(Rect(X,Y,H,W), "Hello!");
}

var ItemA : GameObject;
var Inventory : Camera;

function Update ()
{
   Inventory
}

Ok heres the screenshot and this is just a example game for testing some scripts.

In the recipe arr i put the size to two. and each elements has their own and the Ingridients arr i put to 4 gameobject’s as you can see the picture above. And when i craft the item like element 0 it cant craft. Any mistakes with this? Sorry if my english is bad and here’s another ScreenShot for you.

var ItemDispenser : GameObject;
class Recipe{
var Ingredients : String;
var FinalItem : GameObject;
}
var RecipeArr : Recipe;
var IngredientsArr : GameObject;

    function Start(){
    	Craft();
    }
    
    function Craft(){
    	
    	for(q = 0; q < RecipeArr.length; q++){
    		var amountCorrect : int = 0;
    		var R : Recipe = RecipeArr[q];
    		var ingrarr : String[] = R.Ingredients;
    		var FItem : GameObject = R.FinalItem;
    		for(p = 0; p < IngredientsArr.length; p++){
    			var IngrName :String = IngredientsArr[p].name;
    			for(i = 0; i < ingrarr.length; i++){
    				var IngriedientStr : String = ingrarr*;*
  •  		if(IngriedientStr.Equals(IngrName)){*
    
  •  			amountCorrect++;*
    
  •  			Debug.Log(IngrName);*
    
  •  			if(amountCorrect == ingrarr.length){*
    
  •  				Instantiate(FItem, ItemDispenser.transform.position, ItemDispenser.transform.rotation);*
    
  •  			}*
    
  •  		}*
    
  •  	}*
    
  •  }*
    
  • }*
    }
    You just have to add the gameobjects you want to use for crafting to the IngridientsArr and then call the Craft() function either from within the script from another one using SendMessage(Craft);
    Hope this helps.
    PS:
    Code Snippet to craft when Clicked:
    var hit : RaycastHit;

function Update(){

if(Input.GetMouseButtonDown(0)){ //Checks if Left Mouse Button is pressed. Right Mouse Button is 1
if (Physics.Raycast (transform.position, transform.forward, hit, 100)) { //Sends out a 100 units long raycast from the position and rotation of the GameObject it’s attached to. Hit stores information about the Object the Raycast hits
if(hit.transform.gameObject.name == “CraftingBench”){ //Checks if Name of Object you’re looking at is CraftingBench. Could also be used with tag: hit.transfom.gameObject.tag
hit.transform.gameObject.SendMessage(“Craft”); //calls function Craft() on Object you hit with raycast

}
}
}

*} *
Put this snippet either in a new Script and attach this to the Camera or paste the content of the Update function in any Update function of a scipt you already have attached to the Player Camera.
Change CraftingBench to whatever Name your Crafting GameObject has or change this line to:
if(hit.transform.gameObject.tag == “CraftingBench”) if you have a tag on this gameObject.
I didn’t test this Code so if have a problem with it you can not solve just let me know. I would also recommend you to look over all the code I posted to see how it works so that you can understand it.
[http://dl.dropbox.com/u/83937500/Crafting%20Example.unitypackage][1]
Here is the Link of a Unity Package containing an example of the scripts in action. Just make a new Project an then Import the Crafting Example.unitypackage. Then load the CraftingHelpScene and hit Play. When the scene started just look at the floating Cube called Crafting Bench and left click. A Cube should pop out and fall on the ground. You can only do this ones as the Materials used for Crafting get destroyed and the IngredientsArr-Array gets cleared.
I also made some Improvements to the Crafing script:
- If there are more Ingredients in the Array then needed in any Recipe it’s not possible to craft anything.
- The Gameobject used in a Recipe will get destroyed after the Final Item was crafted.
- The Ingredients-Array gets cleared after crafting.
[1]: http://dl.dropbox.com/u/83937500/Crafting%20Example.unitypackage