Inventory, need help assigning item to slot

i have been working on an inventory system for a few hours and at the moment i have 2 items and 2 slots and this is how i assign them…

function AddPotH(){
	if(slot01_free){
		slot01_icon = Pot_health;
		Pot_health_int++;
		slot01_int++;
		slot01_free = false;
	}
	else if(slot01_free == false  slot02_free == true  slot01_icon == Pot_mana){
		slot02_icon = Pot_health;
		Pot_health_int++;
		slot02_int++;
		slot02_free = false;
	}
	else if(slot01_free == false  slot02_free == true  slot01_icon == Pot_health){
		Pot_health_int++;
		slot01_int++;
	}
	else if(slot01_free == true  slot02_free == false  slot02_icon == Pot_health){
		Pot_health_int++;
		slot02_int++;
	}
	else if(slot01_free == false  slot02_free == false  slot01_icon == Pot_health){
		slot01_icon = Pot_health;
		Pot_health_int++;
		slot01_int++;
	}
	else if(slot01_free == false  slot02_free == false  slot02_icon == Pot_health){
		slot02_icon = Pot_health;
		Pot_health_int++;
		slot02_int++;
	}
	else{
		Debug.Log("Out of Bag space!");
	}
}

a lot of script to assign just one item to any of two slots right

there must be an easier way… how can i script just a simple bit of code that checks weather the item you picked up is already assigned to any slot and if so adds it there (if it is stackable)
if not to assign it to the first empty one?

Please edit your post with ‘code’ tags.

They are [/code] in reverse order.

Your best bet is to make the inventory an array of slots, then iterate through the slots to check if they’re empty.

please elaborate, how do i create an array?

class Item{
var id=0;
var name="";
var description="";
}
var inventory = Array();
var item=Item();
item.id=123;
item.name="Benjamin's Nifty Spectacles";
item.description = "This item allows you to clearly see what has happened in the past, but does nothing about what you are doing in the future.";

inventory.Add(item);
//or
inventory[0] = item;
//or
var inventoryCount=14; //14 slot inventory
for(var i = 0; i<inventoryCount; i++){
if(inventory[i]==null){
inventory[i]=item;
i=inventoryCount;
}
}

You can take a look at my open source inventory http://forum.unity3d.com/threads/48229-RPG-Inventory-Source see how it works and use what you need.