Advertisement
FlyingFrog

Inventory

Dec 26th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerInventory : MonoBehaviour
  6. {
  7.     [SerializeField] private List<string> _items;
  8.  
  9.     public void AddItem(Item item)
  10.     {
  11.         _items.Add(item.ItemName);
  12.     }
  13.  
  14.     public void RemoveItem(Item item)
  15.     {
  16.         _items.Remove(item.ItemName);
  17.     }
  18.  
  19.     public bool HasItem(string itemName)
  20.     {
  21.         if (_items.Contains(itemName))
  22.         {
  23.             _items.Remove(itemName);
  24.             return true;
  25.         }
  26.         else
  27.         {
  28.             return false;
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement