Inventory help - Never used GUI before.

Hello everyone. I’ve just downloaded a very simple inventory system for my game.
I have everything worked out its just I don’t really like the way its setup.

I’ve never used anything to do with GUI properly before and I want to learn.

What I want is to know how to setup my inventory to look at least half decent.
At the moment its just an 5x8 set of box’s with the WoW backpack texture :slight_smile:

I want to know how I can add a top part to it.


|| <----- top bar with text etc.
|
|
|| <----- these are my slots.
|
|
|________|

I also would like to know how I would add a background around it that scales depending on how many slots there are.
This is what it looks like up to now →

Here is what happens when I pick something up, the texture is replaced by another, I want it to sit on top so it doesn’t disappear.

I don’t really want someone to do it for me. I want someone that can explain how to do it to tell me what sort of things I can do with GUI (inv related)

Also I wanted to do an equipment thing like on wow with head, neck etc in a separate window.
but use the same kind of system I have for my inventory.

Here’s the code for my inventory in case you need it to explain.

static var statInventory : Inventory;



public var drop_point : Transform;



//Our inventory

var inventory : Array;





//This will be drawn when a slot is empty

public var emptyTex : Texture;



//the size of the inventory in x and y dimension

public var inventorySizeX = 4;

public var inventorySizeY = 4;



//The pixel size (height and width) of an inventory slot

var iconWidthHeight = 40;



//Space between slots (in x and y)

var spacing = 4;



//set the position of the inventory

public var offSet = Vector2( Screen.width / 2, Screen.height / 2 );



// TEST VARIABLES

// Assign these to test adding Items

public var testTex : Texture;

public var testTex2 : Texture;



public var testInvObject : GameObject;

public var testInvObject2 : GameObject;



//Our Representation of an InventoryItem

@System.Serializable

class InventoryItem

{

   //GameObject this item refers to

   var worldObject : GameObject;

   //What the item will look like in the inventory

   var texRepresentation : Texture;

}



// Create the Inventory

function Awake()

{

	statInventory = this;

	

   inventory = new Array(inventorySizeX);

   

    for( var i = 0; i < inventory.length; i ++ )

    {

        inventory[i] = new Array(inventorySizeY);

    }

}



function OnGUI()

{

    var texToUse : Texture;

    var currentInventoryItem : InventoryItem;

   

     //Go through each row

     for( var i = 0; i < inventory.length; i ++ )

     {

         // and each column

         for( var k = 0; k < inventory[i].length; k ++ )

         {

             currentInventoryItem = inventory[i][k];

           

             //if there is an item in the i-th row and the k-th column, draw it

             if( inventory[i][k] == null )

             {

                 GUI.DrawTexture( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), emptyTex );

             }

             else

             {

             	GUI.DrawTexture( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), currentInventoryItem.texRepresentation );

             }

             

           	 if(currentInventoryItem != null  

           	    GUI.Button( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), "", GUIStyle("label") ))

             {

             	

             	currentInventoryItem.worldObject.transform.position = transform.position;

             	currentInventoryItem.worldObject.transform.rotation = transform.rotation;

             	currentInventoryItem.worldObject.active = true;

             	

             	if(Input.GetMouseButtonUp(0))

             	{		

             		//Equip it

             		inventory[i][k] = null;	

             		currentInventoryItem.worldObject.transform.parent = null;

             		

             	} else if(Input.GetMouseButtonUp(1))

             	{

             		//Drop it

             		inventory[i][k] = null;	

             		currentInventoryItem.worldObject.transform.position = drop_point.transform.position;

      

             	}

             }

         }

    }

    

  /*  if( GUILayout.Button("AddItem1"))

    {

    	var newInvObj = Instantiate(testInvObject, Vector3.zero, Quaternion.identity);

    	newInvObj.active = false;

        AddItem( newInvObj, testTex );   

    }

   

    if( GUILayout.Button("AddItem2"))

    {

        var newInvObj2 = Instantiate(testInvObject2, Vector3.zero, Quaternion.identity);

    	newInvObj2.active = false;

        AddItem( newInvObj2, testTex2 );      

    }  

    */ 

}



function AddItem( item : InventoryItem )

{

    //Go through each row

    for( var i = 0; i < inventory.length; i ++ )

    {

        // and each column

        for( var k = 0; k < inventory[i].length; k ++ )

        {

           //If the position is empty, add the new item and exit the function

           if( inventory[i][k] == null )

            {

                inventory[i][k] = item;

                return;

            }

        }

    }   

   

    //If we got this far, the inventory is full, do somethign appropriate here   

}



function AddItem( worldObject : GameObject, texRep : Texture )

{

   var newItem = new InventoryItem();

   

   newItem.worldObject = worldObject;

   newItem.texRepresentation = texRep;

      

   AddItem( newItem );   

}

try this :slight_smile:
http://forum.unity3d.com/threads/90871-advanced-inventory-system-example

If your inventory is static in size, just put a background texture that covers everything and then put stuff over it.

wow thank you :slight_smile: exactly what i needed.