Non-GUI inventory system

Hello, I realize there have been quite a lot of posts on inventory systems, but I just can’t wrap my head around the solution, in the context of what I am trying to achieve. That being said, I’m doing this to better my understanding of programming as I’m a beginner in unity (and coding in general), so providing as much information as you’re willing to type up is something I’m appreciative of. I’m really looking to understand the concept behind creating an inventory (and generally, just storing data) so I can figure out different methods of creating them myself, as well as twist and turn other methods. I’ll show you what I have so far to better communicate the question I am asking.

switch (Input.inputString) {
            //Can't figure out how to add items to the selected slots
        case "1":
            selectedSlot = eqSlots.hands;
            break;
        case "2":
            selectedSlot = eqSlots.leftArm;
            break;
...
        case "7":
            selectedSlot = eqSlots.rightBack;
            break;
        }

So, here I have something to select which slot on the player is currently active.

switch (selectedItem){
            //Do something based on which item is equipped
        case tools.hands:
            break;
        case tools.weapon:
            break;
        case tools.hammer:
            break;
        case tools.crucible:
            break;
        case tools.hoe:
            break;
        case tools.ingot:
            break;
        }

And here I have something on a different game object that will decide what to do based on which item is selected in the slot. But the actual problem is, I don’t have any way to actually store the item that is selected (which I want to be a game object). I really feel like the solution is on the tip of my fingers, but I’m missing something. Hence my question, can one of you smart gurus school me on how to store and access specific game objects effectively?

public class InventoryManager
{
//Keep a reference to the currently equipped item
   private GameObject equippedItem;

//Set the reference to the currently equipped item
public void equip(GameObject objectToBeEquipped)
{
equippedItem.SetActive(false); //disable currently equpped item
equippedItem = objectToBeEquipped;//set the new equipped item
equippedItem.SetActive(true); //activate the new equipped item
}


public void LateUpdate()
{
   //Continuosly hold it in front of camera
   HoldItem();

}

//Hold it infront of the camera
private void HoldItem()
   {


     Vector3 cameraPosition = <camera position>
     Quaternion cameraQ = <camera quanternion>
     Vector3 distanceFromCamera = new Vector3(0.0f, 0.0f, 5.0f);  //5 units infront of camera

//hold it 5units infront of camera
    equippedItem.transform.position = (cameraQ * distanceFromCamera) + cameraPosition;
     equippedItem.transform.LookAt (<camera posiiton>); //continously have the object look at the camera so it doesnt appear to rotate


   }
1 Like