Get distance between moving object and a static one?

I know there have been many question on this. I have read through about each and every one of them and I didn’t find an answer to this.

I’m not sure if the title is exactly correct as I do know how to get the distance between 2 points but I’d like to get the distance between 2 objects.

13587-example_image.png

The problem in the image above, is that my AI Enemy gets a different distance when it moves left or right although I would think it would be normal for the distance not to chance when it moves left or right but upwards or downwards.

I have made my distance computation work with both Raycast, Linecast, Vector2.Distance, Vector3.Distance & Vector3.Angle but the same problem happens to me with all of these mentioned solutions. Could it be due to the fact that the objects are both 3D and I’m thinking as they’d be 2D?

What would my options be here?

I’d compare their x locations, personally.

using UnityEngine;
using System.Collections;
using System;

class CompareLocation : MonoBehavior
{

	public Transform fence;
	public Transform AIChar;
	
	public double fenceX = fence.position.x;
	public double AICharX = AIChar.position.x;
	public double minDist = 10.0;
	
	void Update()
	{
	
		if(fenceX - AICharX > minDist)
			// Code
	
	}
}