Stop Moving at a Certain Distance from a Hit Box

I’m having a problem with my fighting game which has to do with an interaction between two objects: a guarding character and an attacking “hit box.” What I want to do is have the character stop moving when a hit box prefab has its type variable set to “attack”. I have no idea how to do that though. Is there a way that I can not only find another object, calculate distance, and also access its variables or is there a better way to do it? I’ve tried starting with:

hitBox = GameObject.FindWithTag("hitBox");
 		if(hitBox.GetComponent("hitBox").GetType == "attack" || hitBox.GetComponent("hitBox").GetType == "projectile"){
 			Debug.Log(GameObject.FindWithTag("hitBox").transform.position);
 		}

But this returns an NullReferenceException error and nothing is printed onto my debug log. I’ve also tried just GameOjbect.Find, but that didn’t work either. My question might be a little confusing, so even if you’re unsure exactly what I’m trying to ask, any help is appreciated.

you could try putting a collider on your character that’s the size of the area or distance you want and use it as a trigger.