Move when Raycast

Basically, I want an object to move when it hits the player with a raycast. How can I go about this?
So just using Transform.Translate and RaycastHit. Don’t link to the docs, I’ve already looked there, and would like some specific code.

Just attach this to a box or something. The object will “run” from you.

var speed : float = 0.1;

function Update()

{

var direction = transform.TransformDirection(Vector3.forward);

var hit : RaycastHit;

if (Physics.Raycast(transform.position, direction, hit, 100))

{

 if(hit.collider.gameObject.tag=="Player")

 {

      transform.Translate(0, 0, -speed * Time.deltaTime);

 }

}

}