Why would gameObject.name work, but gameObject.GetComponent not?

Hi all,

I am trying to detect if a GameObject is being touched and to call a method on it to select it, but I cannot seem to get the instance of it. Here is what I have:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TouchHandler : MonoBehaviour {
	Detective d;
	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) 
			Vector3 pos = Camera.main.ScreenToWorldPoint( Input.GetTouch(0).position );
			RaycastHit2D hit = Physics2D.Raycast(pos, Vector2.zero);

			if (hit.collider != null) {
				if(hit.collider.name == "Detective"){
					Debug.Log("colldier game object name: " + hit.collider.gameObject.name);
					//Detective d = hit.collider.gameObject.GetComponent<Detective>();

hit.collider.gameObject.name returns “Detective”, but the rest of the commented lines in that scope return a nullreferenceexception. Any one have an idea what might be going on?

That would rather suggest that your GameObject called “Detective” does not have a script called “Detective” attached to it…?