Using raycast to "collide" with tagged objects & enable Halo Component

I get the null reference exception for the hit.transform.gameObject.tag:

using UnityEngine;
using System.Collections;

public class SelectObject : MonoBehaviour {
	RaycastHit hit;
	GameObject gameObject1;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	    Ray ray = camera.ScreenPointToRay(Input.mousePosition);
        Debug.DrawRay(ray.origin, ray.direction * 100, Color.green);
		
		 if(Physics.Raycast(ray,100))
			{
			print ("Here is an object!");
			if (hit.transform.gameObject.tag == ("Ground")){
				Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);
				print ("You Hit the Ground");
			}
			else if (hit.transform.gameObject.tag == ("Player")){
				Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue);
				gameObject.GetComponent<Halo>().enabled = true;
				print ("You touched the Players object");
			}
			else{
				print ("At least you hit something");
			}
			}
			
	}
	
}

What am I missing here? Also I wanted to enable a component(Halo - by default it is disabled) of the Player’s object when the raycast collides with it(Indicating I could select the object when the raycast collides with the tagged object by highlighting it with a halo)

You must change line 17 to this:

if(physic.raycast(ray,out hit,100))

Thanks to → Bigbat and ExtheSea for pointing out what I was missing for the raycasting. Turns out I missed putting a “out hit” on physic.raycast on line 17. I figured that some people can’t seem to use the halo component so its better to use a component which does a similar effect which is the light component with the draw halo checkbox → checked. This is what I did to enable the highlight when clicked.

using UnityEngine;
using System.Collections;

public class SelectObject : MonoBehaviour {
	RaycastHit hit;
	public Light myLight;
	// Use this for initialization
	void Start () {

	
	}
	
	// Update is called once per frame
	void Update () {
	    Ray ray = camera.ScreenPointToRay(Input.mousePosition);
        Debug.DrawRay(ray.origin, ray.direction * 100, Color.green);
		
		 if(Physics.Raycast(ray, out hit, 100))
			{
			print ("Here is an object!");
			if (hit.transform.gameObject.tag == ("Ground")){
				Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);
				print ("You Hit the Ground");
			}
			else if (hit.transform.gameObject.tag == ("Player")){
				Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue);
				if ((Input.GetMouseButtonDown(0))&&(hit.transform.gameObject.tag == "Player")){
					print("You Clicked the Player!");
					GameObject light = GameObject.FindWithTag("Player");
					myLight = light.GetComponent<Light>();
					myLight.enabled = true;
				}
				else{
					//ObjLight.light.enabled = false;
				}
				//gameObject.GetComponent<"Halo">().enabled = true;
				print ("You touched the Players object");
			}
			else{
				print ("At least you hit something");
			}
			}
			
	}
	
}

So Basically I “get” the component of a gameObject tagged Player and enable it:

					GameObject light = GameObject.FindWithTag("Player");
					myLight = light.GetComponent<Light>();
					myLight.enabled = true;