I have been working on trying to create a inventory system and crafting system for my player , i downloaded the invenrory master asset from the store but i dont like it at all because when a item is added to the inventory slot its a item prefab which the modular building system for somereason doesnt work with that .
I was wondering what steps do i need to take in order to create or script a inventory for my player i have the items script which has
The item icon
The items name
the items gameobject
The ability of the item
The type of item
And the rarity of the item
All of those have a script
My item type script item ability item rarity and so on
I also have a script that defines the id number for the items as well as defines the item id for the items that get picked up
I already have the inventory screen set up with the slots that are numbered 1-28 and is working now i just need to beable to pick the items up and add them to my inventory but when they get added i want them all to have their own names so if i pick up a apple it will be the game objects prefab name which is appleprefab
what lefty righty said is correct but doesn’t answer the question in total.
You should make a list or dictionary to where you can add all items to so you get a list of your items, after that is done you can make another list for your inventory and grab the items out of the item list.
and from those scripts the answer appears to be “no” but you’re heading in the right direction from the looks of the item script.
in unity you tend to start with “everything is a gameobject” and “all scripts are components inheriting from mono behaviour” which is fine up to a point. Then you run into “but I don’t want it to exist in the scene, but I want to know about it” and you have to split things up.
using UnityEngine;
public class Item
{
public string name;
public int id;
public GameObject go;
public Item()
{
// handle constructor stuff here
}
}
note the complete lack of inheritance. This is just a “normal” c# object, you can store these in your inventory lists/arrays and hold the information about what is in the container. The “go” is used when you want it to exist in the world, you can instantiate the gameobject, i.e. take something out of the container and put it into the characters hand / drop it into the scene etc.
The next question is, “ok, we have these class/objects to hold the item information but where do we store them?!”… and that is when we introduce ScriptableObjects.
The bergzerg arcade is a good example, but the html code on the webpage is borked They have done a much longer (more complicated and in depth) tutorial on items systems on their youtube channel.