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)**
↧