Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

"object reference not set to an instance of an object"?

$
0
0
I'm trying to make it so that an object is destroyed when hit by this raycast. But when i press e, activate the raycast and hit the object, unity just gives back "object reference not set to an instance of an object". What does this error mean and how can i fix it? Code here: if (Input.GetKeyDown(KeyCode.E)) { RaycastHit hit; Ray forwardRay = new Ray(player.transform.position, transform.forward); if ((Physics.Raycast(forwardRay, out hit, 100)) & hit.collider.CompareTag("interactable")) { Destroy(hit.transform.gameObject); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>