'How to add items to player inventory

I am having trouble with a project for class. I am having to add items to the player inventory. I'm new to this and just having a hard time understanding the instructions and implementing it into my code. If someone can help dumb it down for me and explain to me what code I will be adding or helping me to understand it that will be great. Here are the instructions I'm having trouble understanding,

Next, create an instance (a variable) of Inventory in Robot Kyle's Movement Script. Don't forget to initialize it in the constructor. Now, create a method to add items to the List. The method should take in a Transform as a parameter (called t). To add to a list, call its Add( ) method and pass the thing you want to add, which in this case would be items.Add(t); Create a public method called AddToInventory( ) that takes in Transform as a parameter and adds it to the list. After adding t to the list, set it to be inactive by calling t.gameObject.SetActive(false); This way, the game object will no longer be seen

Just having trouble understanding how to do what it is asking. Here is the two scripts we are using, an Inventory script and MovementScript

MovementScript:

using UnityEngine;
using System.Collections;


public class MovementScript : MonoBehaviour 
{
    Animator anim;
    public float runSpeed = 2.0f;
    public bool isActive = true;
    private float h = 0.0f; // Horizontal input (A, D)
    private float v = 0.0f; // Vertical input (W, S)
    private float vAbs, hAbs, maxInput; // The absolute value of the input
    private float dfs = 0.0f; // The direction the character is facing
    private float radsToDegs; // A conversion between radians and degrees
    private var Inventory;
    // Use this for initialization
    void Start () {
        anim = GetComponent<Animator>();
        anim.SetFloat("Speed", 0.0f);
        radsToDegs = 180.0f/(float)Mathf.PI;
    }

    void OnTriggerEnter(Collider other) {
        Debug.Log("Trigger "+other.tag);    
    }

    // Fixed Update is called once per frame
    void Update () {
        if (!isActive) {
            anim.SetFloat("Speed", 0);
            return;
        }
        
        h = Input.GetAxis("Horizontal");
        v = Input.GetAxis("Vertical");
        vAbs = Mathf.Abs(v);
        hAbs = Mathf.Abs(h);
        maxInput = Mathf.Max(vAbs, hAbs);
        
        anim.SetFloat("Speed", maxInput);
        if ((vAbs>0.1)||(hAbs>0.1f)) {
            dfs = Mathf.Atan2(-v, h);
            Vector3 lookAtTarget = Quaternion.AngleAxis(dfs*radsToDegs, Vector3.up)*Vector3.forward + transform.position;
            transform.LookAt(lookAtTarget);
            transform.Translate(Vector3.forward*Time.deltaTime*maxInput*runSpeed);
        }
    }
}

Inventory Script

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

public class Inventory
{
    public List<Transform> items;

    public Inventory()
    {
        items = new List<Transform>();
    }
}



Solution 1:[1]

You can follow brackeys tutorial

You should separate your movement and general interaction scripts.

Generally, You should add script to your player and:

  1. Get mouse clicked item, (You can create Item class and extend from this class)
  2. Add this to item to your inventory
  3. Remove item from world. (use Destroy(gameObject))

Basically, your inventory is simple List or Array of Items

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gguney