Hello All,
My name is anthony faraci and im in need of a bit of help…Ive been programing and scripting for 5 almost 6 years, but im having a bit of a problem with my inventory system. I have the inventory itself working and the pick up of items, but i cant seem to figure out how I could drop the items.
Here are my Scripts:
This is attached to the Item itself:
public var InventoryIcon : Texture2D;
public var ItemDescription : String;
public var ItemClass : String;
public var defence : int;
public var damage : int;
var doWindow : boolean = false;
function OnMouseOver() {
doWindow=true;
}
function OnMouseExit() {
doWindow=false;
}
function OnGUI() {
if (doWindow)
GUI.Window (0, Rect (110,10,200,80), DoWindow, "Info");
}
function OnMouseDown() {
var inv = FindObjectOfType(inv2);
inv.AddItem( gameObject, InventoryIcon );
Network.Destroy(this.gameObject);
Debug.Log("item picked");
}
function DoWindow (windowID : int) {
GUI.Label (new Rect(5, 15, 200, 25), "Item:" + ItemDescription);
GUI.Label (new Rect(5, 30, 90, 25), "Class:" + ItemClass);
GUI.Label (new Rect(5, 45, 90, 25), "Defence:" + defence);
GUI.Label (new Rect(5, 60, 90, 25), "Damage:" + damage);
}
This is Put on the player:
var inventory : Array;
var doWindow : boolean = false;
public var emptyTex : Texture;
public var inventorySizeX = 4;
public var inventorySizeY = 5;
var iconWidthHeight = 40;
var spacing = 4;
public var offSet = Vector2( 100, 100 );
private var itemImage : Texture2D;
class InventoryItem
{
var worldObject : GameObject;
var texRepresentation : Texture2D;
}
function Awake()
{
inventory = new Array(inventorySizeX);
for( var i = 0; i < inventory.length; i ++ )
{
inventory *= new Array(inventorySizeY);*
}
}
function OnGUI() {
var texToUse : Texture2D;
var currentInventoryItem : InventoryItem;
for( var i = 0; i < inventory.length; i ++ )
{
for( var k = 0; k < inventory*.length; k ++ )*
{
texToUse = emptyTex;
currentInventoryItem = inventory*[k];*
if( inventory*[k] != null )*
{
texToUse = currentInventoryItem.texRepresentation;
}
_ var it = GUI.Button( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), texToUse );
GUI.Button( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), texToUse );
* var w : int = 0;
var h : int = 0;
if (it){//&& (inventory[k]==!null){*_
* //This is were the drop item command would go*
* }*
}
}
}
function AddItem( item : InventoryItem )
{
for( var i = 0; i < inventory.length; i ++ )
{
for( var k = 0; k < inventory*.length; k ++ )*
{
if( inventory*[k] == null )*
{
inventory*[k] = item;*
return;
}
}
}
}
function AddItem( worldObject : GameObject, texRep : Texture2D )
{
var newItem = new InventoryItem();
* newItem.worldObject = worldObject;*
* newItem.texRepresentation = texRep;*
AddItem( newItem );
}
Any help would be much appreciated!