Dynamically assign a value to game property
always ------------This python 

it will set distance.

import bge
from mathutils import Vector
cont = bge.logic.getCurrentConroller()

own = cont.owner

offset = Vector([100,0,0])

offset = own.worldPosition+(own.worldOrienation*offset)

##offset now is a point 100 units out on the objects x axis

Ray = own.rayCast(offset , own.worldPosition, 0, '',0,0,0)
## cast a ray to the offset point, 0 units past, looking for any property, not xray and
##  Not returning polydata

if Ray[0]:
## if you hit something
    own['Distance'] = own.getDistanceTo(Ray[1])
## if you dont hit something
else:
    own['Distance'] = own.getDistanceTo(offset)


about scale

in object

always--------------and------------copy distance from raycaster

Distance is changed------python below

import bge
cont = bge.logic.getCurrentController()
own=cont.owner

own.localScale =[1-own['Distance']*.01,1-own['Distance']*.01,1-own['Distance']*.01]


Note,

Ray[1] = world Position Where Ray hit
Ray[0] = who it hit

http://www.pasteall.org/blend/34899