Problems in Unity2D Unity:NullReferenceException: Object reference not set to an instance of an object

Viewed 35

i have problem in Unity:NullReferenceException: Object reference not set to an instance of an object Collectable.OnCollide (UnityEngine.Collider2D coll) (at Assets/Scripts/Collectable.cs:10) Collidable.Update () (at Assets/Scripts/Collidable.cs:24) In these scripts (Collectable and Collidable) I indicated that if the player approaches an object, then that object will change. Please help me. This scripts: enter image description here enter image description here

1 Answers

Maybe your script can't find the player try adding a tag to the player and then on line 10 :

if (coll.gameObject.CompareTag("tagName")){}
Related