Hello I am new to c# and unity so I apologize for these basic questions, but I am making a game and am trying to have it so that when an object is collided they will disappear and be added into an inventory. I am getting this error when I run and collide with the item I want to pick up, :NullReferenceException: Object reference not set to an instance of an object
at MovementScript.AddToInventory (UnityEngine.Transform transform) (at Assets/Scripts/MovementScript.cs:30) and MovementScript.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/MovementScript.cs:26)
so at line 30 and 26 I messed up with the code but looking back I thought I referenced everything. Can someone with a more experienced eye tell me where i went wrong? here is my code
void OnTriggerEnter(Collider other) {
AddToInventory(other.transform.parent);
}
public void AddToInventory(Transform transform)
{
inventory.items.Add(transform);
transform.gameObject.SetActive(false);
}
The error says it is happening at this line AddToInventory(other.transform.parent);
and this line inventory.items.Add(transform);