Distance between 2 objects 1 axis

How can you get The distance, This script is meant to make a vehicle hover, but i really don’t know anything about coding, all i’ve done was a tiny bit of vb a very long time ago.
New script

#pragma strict

function Start () {

}
var hoverHeight : float = 5;

function Update () 
{
var groundLoc = GameObject.Find("ground").transform.position;
var distance = Vector3.Distance(this.transform.position, groundLoc.transform.position);
 
if(distance < hoverHeight, set distance to = hoverHeight at a certain rate;  

{
	
}
}

the problems i need to fix with this are,

  1. on line 11 I get "bce0019: ‘transform’ is not a member of ‘UnityEngine.vector3’.
  2. I’m not sure that will give me the distance i want, as i only want distance in the global y axis.
  3. How is it possible to do the following: if(distance < hoverHeight, set distance to = hoverHeight at a certain rate;

I don’t think that whole thing will work as the transform.position will always be the origin of the ground rather than the part of the ground directly below the vehicle.

You’d be better off using raycasting to detect the distance. Something like this (untested but should work):

var hoverHeight : float = 5;
function Update ()
{
	if (Physics.Raycast (transform.position, Vector3(0,-1,0), hoverHeight))
	{
		rigidbody.AddForce(Vector3(0,10,0));
	}
}

It will pretty much move the vehicle up with a force of 10 if anything’s 5 units below it.

You might find your answer here: http://answers.unity3d.com/questions/252737/hovering-tank.html