replacement of ControllerCollider
Hello there, I am recently learning to build an inventory by following this nice tuto on youtube: link text
For collecting an object to the inventory, there's a player controller built in this tutorial, when the player collide with an object, it would call the inventory.AddItem to do this task. Since I would like to collect object by simply clicking on it, I made a change from original code with OnMouseDown() : IInventoryItem item = hit.collider.GetComponent() to OnMouseDown() { IInventoryItem item = GetComponent().GetComponent(); }
While there's an error message shown each time I click on the object:
NullReferenceException: Object reference not set to an instance of an object HUD.InventoryScript_ItemAdded (System.Object sender, .InventoryEventArgs e) (at Assets/Script/HUD.cs:20) Inventory.AddItem (IInventoryItem item) (at Assets/Script/Inventory.cs:32) Player.OnMouseDown () (at Assets/Script/Player.cs:22) UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
Cannot figure it out since two days, any ideas ? Thank you in advance.