Help with weapon inventory system

so i followed a tutorial on creating an inventory system using scriptable objects and i want now want to create weapons that the player can pick up and use and be stored in that inventory systema nd im lost on how to do that please anyone help, ill attach some of the scripts i used

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu( menuName = "Iventory Item Data")]
public class InventoryItemData : ScriptableObject
{
   public string id;
   public string displayName;
   public Sprite icon;
   public GameObject prefab;

   public ItemType itemType;
   public int damage;
   public float attackSpeed;




   public enum ItemType
   {
    weapon,
    armor,
    consumable,
    other
   }
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class InventorySystem: MonoBehaviour
{
    private static InventorySystem _instance;

    public static InventorySystem Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = FindObjectOfType<InventorySystem>();
                if (_instance == null)
                {
                    Debug.LogError("An InventorySystem instance wasn't found in the scene");
                }
            }

            return _instance;
        }
    }
  public Dictionary<InventoryItemData, InventoryItem> m_itemDictionary;
  public List<InventoryItem> inventory { get; private set; }
 
   public event Action  onInventoryChangedEvent;  // Event for inventory change updates

  private void Awake()
{
   inventory = new List<InventoryItem>();
   m_itemDictionary = new Dictionary<InventoryItemData, InventoryItem>();
}
  public void Add (InventoryItemData referenceData)
  {
    if(m_itemDictionary.TryGetValue(referenceData, out InventoryItem value))
    {
        value.AddToStack();
    }
    else
    {
     InventoryItem newItem = new InventoryItem(referenceData);
     inventory.Add(newItem);
     m_itemDictionary.Add(referenceData, newItem);
    }
    onInventoryChangedEvent.Invoke();
  }
  public void Remove (InventoryItemData referenceData)
  {
     if (m_itemDictionary.TryGetValue(referenceData, out InventoryItem value))
     {
         value.RemoveFromStack();

         if (value.stackSize == 0)
         {
           inventory.Remove(value);
           m_itemDictionary.Remove(referenceData);
         }
     }
      onInventoryChangedEvent.Invoke();
  }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemObject : MonoBehaviour
{
    public InventoryItemData referenceItem ;

    public void OnHandlePickupItem()
    {
        InventorySystem.Instance.Add(referenceItem); 
        Destroy(gameObject);
    }
}
using UnityEngine;

public class PickUpItem : MonoBehaviour
{
    [SerializeField] private LayerMask itemLayer; // Items must be on this layer
    private Camera mainCamera;

    void Start()
    {
        mainCamera = Camera.main;
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            CheckForItemPickup();
        }
    }

    private void CheckForItemPickup()
    {
        Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hitInfo, Mathf.Infinity, itemLayer))
        {
            // Item found!
            if (hitInfo.transform.TryGetComponent<ItemObject>(out ItemObject item))
            {
                item.OnHandlePickupItem();
            }
        }
    }
}

please if anyone can help this is a project and im on a time crunch to finish it

Fastest way will definitely be to start from a short simple inventory tutorial.

Most of what goes into an inventory won’t be the code so much as the setup and design of prefabs and any other things you might use like ScriptableObjects to define your content.

Since inventories are one of the most complicated things you can do, make sure you set a modest goal for your first inventory, perhaps something along the lines of a hotkey bar such as what the first Diablo had. The more features you support, the more abstract and complicated it gets, and it gets complicated fast.

Anything you accomplish will be done one step at a time, just the same way this guy does it:

Imphenzia: How Did I Learn To Make Games:

Here are two tutorials i will recommend for RPG stuff like you are looking for:

Option 1:
(518) CREATE DARK SOULS IN UNITY - YouTube

Option 2:

Pros of Option 1:
-Very comprehensive
-Good C# knowledge

Cons of Option 1:
-Can be a lot for beginners (definitely not impossible)
-He goes VERY fast in some parts and tends to hide functions in VS after typing them
-If you miss a video, you could be missing some necessary parts from the ones you skipped

Pros of Option 2:
-Pretty comprehensive
-Great C# knowledge
-Beginner friendly (with some more intermediate concepts)

Cons of Option 2:
-Some videos are too slow and long
-If you skip a video, you may be needing something from it later (most long tutorial series are like this)
-His Saving/Loading system is outdated. It works, but don’t do it that way, use the one from Option 1, if anything

Note, both can (mostly) be adapted to 3D or 2D. Both tutorials cover what you are looking for. Good luck

1 Like