whats wrong? nullpointer

whats wrong with this code, in my other scene it works perfectly. im trying to use the same code in another script and scene. everytime i run it, it crash instantly.

NullReferenceException: Object reference not set to an instance of an object
RaycasterBasic2.OnGUI () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/RaycasterBasic2.js:46)

here is my code:

	if(hit.collider.gameObject.tag == "cat"){ //<---line 46
	{
		Timer += Time.deltaTime;
		if (Timer > 5) 	
	
	 GUI.Box(Rect(Screen.width / 1.35 - 100, Screen.height / 2 - 100, 300, 150), "CAT", GuiStyle);
	}
  }

place this above line 46

if(hit ==null) Debug.Log("hit is null");
if(hit.collider ==null) Debug.Log("hit's collider is null");

the one that debugs to console is causing the error. I assume your hit returned null because it didn’t hit anything so it collided with nothing.

To prevent

 if(hit && hit.collider && hit.collider.gameObject.tag == "cat"){