How can I find the Distance between Two Objects on the X Axis?

Hi,
I am trying to find a way to find the distance between to points ONLY ON THE X AXIS. By this I mean say my transform.position.x was 5 and my player.transform.position.x was 10, I would receive a result of five. If anybody knows how to do this it would be much appreciated if you could let me know how.

Many Thanks,

Tommy Eaves

Hi.
you actually need to use Mathf.Abs, this way it always gives a positive value:

float dist = Mathf.Abs(object1.transform.position.x - object2.transform.position.x);

float dist = object1.transform.position.x - object2.transform.position.x;

Distance from one point to another : point2 - point1. Then just get the x property