Hi, I have been making a 2D platform game, and it currently all runs exactly how I want it to, but I’m getting an error all the same. It doesn’t stop the game performing correctly, so I’m not sure how to fix it.
The error is
NullReferenceException: Object reference not set to an instance of an object
PickupController.CollectPickup () (at Assets/Scripts/PickupController.cs:39)
and it relates to this if statement:
if (hitRear1.collider.tag == "Player" || hitFront1.collider.tag == "Player" || hitBottom1.collider.tag == "Player" || hitTop1.collider.tag == "Player")
I’ve searched through the forums and found that the error relates to a reference not referencing anything, and I know that my collision detection will return null tag values if no collision is detected, but I don’t know what to do to get rid of the errors. If anyone can help, I’d be very grateful.
Thanks!