Raycast: Different results depending on distance


I’m wondering if I can get different results depending on the distance of a raycast?

This is what I want to do:

I want to display a GUI Text when 1 meter from the collider, but it won’t disappear until I’m 1 meter from another collider. I want the GUI Text to disappear at a longer distance.

Is this at all possible?

Of course it is possible.

function Update () {

	var hit : RaycastHit;

	if (Physics.Raycast (transform.position, -Vector3.up, hit,1)) {

		var distanceToOtherobject= hit.distance;



Then inside ongui function do something like

If (distancereached==true)

Show ur GUI text

Hope u get the idea