- Home /
Question by
Checkseven · Jan 28, 2015 at 11:28 AM ·
javascriptlistclassinventoryunity 4.6
How can i store the Amount of an item i have in an inventory?
Hey guys, I'm sort of-kinda new to js so i'm sorry if i sound like a complete nub, But i'm a bit stuck here. I Have the basic inventory set up using a list and a class, i'm trying to figure out how to add 1 to the amount of that item in the inventory. (If the item exists in the inventory add +1 to the existing one, if it does not exist or the existing item's amount has reached the stack limit add another to the list) sort of thing.
Here's the Item code(JS)
public class Item{
var Name : String;
var Desc : String;
var Limit : int;
var Rarity : Rarity;
var Group : Group;
}
enum Rarity {
Never,
Rare,
Common
}
enum Group {
None,
Food,
Drink,
Tool,
Weapon,
Misc
}
and here's the Inventory code (JS)
import System.Collections.Generic;
var Items : Item[];
var Content : List.<Item> = new List.<Item>();
function Add(ID : int){
Content.Add(Items[ID]);
//Code to search for the item in the content list and add + 1 to it?
Debug.Log ("Added "+Items[ID].Name);
}
Thankyou!
Comment