Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Inventory
- {
- private List<Item> contents = new List<Item>();
- public bool Add(Item item)
- {
- // returns true for success, false if could not add
- if (contents.Contains(item))
- {
- Debug.Log("Cannot add "+item.name+" to inventory. An equal item is already present!");
- return false;
- }
- else
- {
- Console.WriteLine("Adding "+item.name+" to inventory");
- contents.Add(item);
- return true;
- }
- }
- }
- public class Item : IEquatable<Item>
- {
- private static int idIndex = 0;
- public string name;
- public Item(string name)
- {
- this.name = name;
- ID = idIndex++;
- }
- public bool Equals(Item other)
- {
- return (this.ID == other.ID);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment