I’m making an inventory system for my game. It’s differs from most in the way that the items are pretty much treated like weapons are treated in FPS games. You pick an item up and the character will hold it in front of the camera while running around and you should be able to scroll through the items using the mouse wheel. The inventory system is a modified version of Xeno360’s one (http://forum.unity3d.com/threads/53599-My-Contribution-Inventory-System-Free).
What I don’t know is how to get the element number and name from an object in my inventory array. I have an int variable called currentWeapon that I wanna sync with the array’s element’s number and objectname. Ex. I have three objects: Element 0 - dagger, Element 1 - jar, Element 2 - axe. When currentWeapon == 2 I want the axe to be the “active” object.
Parts of the code:
Inventory Script:
var Contents: Transform[];
function AddItem(Item:Transform)
{//Add an item to the inventory.
var newContents=new Array(Contents);
newContents.Add(Item);
Debug.Log(Item.name+" has been added to inventroy");
Contents=newContents.ToBuiltin(Transform);
}
Item Script:
function OnMouseDown()
{//When you click an item
var playersinv=FindObjectOfType(Inventory);//finding the players inv.
playersinv.AddItem(this.transform);
MoveMeToThePlayer(playersinv.transform);//moves the object, to the player
particle.layer = 13;
}
Thanks in advance