Distance between 2 objects help

public float particleSpeed=20;
public GameObject target;
float distance;

	void Start ()
	{
		Transform targetTransform;
		target = GameObject.FindGameObjectWithTag("SHC");
		print (target.name.ToString());
		targetTransform = target.transform;
		transform.LookAt(targetTransform);
	}

	void Update ()
	{
		transform.position = transform.position + (transform.up * Time.deltaTime * Hub.timeScale * particleSpeed);
		distance = Vector3.Distance (this.transform.position, target.transform.position);
	}

I need to know the distance between the object this script is attached to and the object tagged with “SHC”. What i did doesn’t work, anyone know why?

UnassignedReferenceException: The variable part of SHC has not been assigned.

The code you wrote should work aas long as the target gameobject is actually found. Is it?

Edit: I guess not, so you need to check if you wrote teh tag string exactly as it appears in the list of tags available in the game.