Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public class Inventory : MonoBehaviour
  2. {
  3. public List<GameObject> itemsGOInInventory = new List<GameObject>();
  4.  
  5. public void AddItem(GameObject itemToBeAdded)
  6. {
  7. itemsGOInInventory.Add(itemToBeAdded);
  8. Destroy(itemToBeAdded);
  9. }
  10.  
  11. public void FindItem(string name)
  12. {
  13. foreach (GameObject item in itemsGOInInventory)
  14. {
  15. if (item.GetComponent<Item>().itemName == "pistol")
  16. {
  17. Instantiate(item.GetComponent<Item>().itemObject, this.transform);
  18. }
  19. }
  20. }
  21. }
  22.  
  23. public class InventoryItem
  24. {
  25. string name;
  26. string description;
  27. string spritePath;
  28. // other variables
  29. }
  30.  
  31. public class InventoryItemView : MonoBehaviour
  32. {
  33. public InventoryItem item;
  34. // ...
  35. }
  36.  
  37. public class Inventory : MonoBehaviour
  38. {
  39. public List<InventoryItem> itemsGOInInventory = new List<InventoryItem>();
  40.  
  41. public void AddItem(GameObject itemToBeAdded)
  42. {
  43. itemsGOInInventory.Add(itemToBeAdded.GetComponent<InventoryItemView>().item);
  44. Destroy(itemToBeAdded);
  45. }
  46. //...
  47. }
  48.  
  49. itemToBeAdded.SetActive(false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement