How to perform some code if you are close to an object

Hey guys,
I am trying to make a script that when you are close to an object, it prints some GUI to the screen.

But what I am having trouble with is figuring a way to check if you are in a certain range of an object…
I know you can do this somehow with raycasting, but I’m not sure how to do it…

Any help would be greatly appreciated!!!

-Grady

the most easy way to approach this will be to make a cube around the object(the one on which you need to print a gui)make it a trigger the size of the cube will depend upon the range you want .

then apply the following code on the cube

function OnTriggerEnter(info : Collider)
{
     if(info.gameObject.tag == "your object tag")
    {
         // do your required work here....
    }
}

This is a modified library function that i have written for these things.
Call it from an update function in some script and it should work.
Hope this is around what you were looking for!

def FindObjectWithTag(newPosition as Vector3, tag as string, objectRadius as double):
        		ColliderList = Physics.OverlapSphere(newPosition, objectRadius)	
        		resultObject as duck = null
        		for listObject in ColliderList:
        			if listObject.tag == tag:
                         return true
        				 //resultObject = listObject 
        		//return resultObject.gameObject
                return false