Using raycasters to freeze enemies

I found out about raycasts recently, and I want to try and use one to make the player’s phone light freeze enemies in place when it touches them by casting a ray from the phone that sends a message to enemies when it touches them to stop all movement and animation until the ray isn’t touching them anymore. The problem is I have almost no experience with Javascript or C#, so I have no idea what I’m doing S: I’ve looked at plenty of tutorials, but none have exactly what I need. Would anyone be able to help, maybe come up with a raycasting script I could go off of?

This is all I have for my raycast script.

#pragma strict

private var lineTransform : Vector3;
private var startTransform : Vector3;

function Start ()
{
	lineTransform = transform.position;
	startTransform = transform.position;
}

function Update () {

var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5,0));
	if (Physics.Raycast (ray, hit, 100)) {
    Debug.DrawLine (ray.origin, hit.point);
	}
		//Debug.DrawRay(startTransform, lineTransform, Color.red);
}

There’s not really anything there, except a blank ray.

You won’t see anything because rays originate at the camera, what reduces them to a single point in the 2D screen - at most a single pixel will be lit at the center of the screen, in this case.

You could try something like this instead:

...
if (Physics.Raycast (ray, hit, 100)) {
    print("Freeze, "+hit.transform.name);
}

This will print “Freeze” + target’s name whenever your ray hits some object. If it’s ok, you can go a step further by replacing this instruction with a SendMessage:

if (Physics.Raycast (ray, hit, 100)) {
    hit.transform.SendMessage("Freeze", SendMessageOptions.DontRequireReceiver);
}

This code will try to call the function Freeze() in any script attached to the target (does nothing if such function doesn’t exist).