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

Help with raycast!!

$
0
0
I need to set a script that when i click on the Enemy gameObject appears, in top of the screen , the life and the name of the Enemy.... Now i' am using the raycast: ---------- void Update () { if (Input.GetMouseButtonDown (0)) { Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); RaycastHit hit; if (Physics.Raycast (ray, out hit, 100)) { if (hit.collider.gameObject.tag == "Enemy") print ("enemy hit"); } } } But this error appears every time i click : ---------- **NullReferenceException: Object reference not set to an instance of an object EnemyManager.Update () (at Assets/Scripts/EnemyManager.cs:14)**

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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