I need help on how to make a Aim Assist aka Auto AIm

I want to make it so when the player aims at a enemy (within x number of feet of the enemy) the aimmer will snap to the target, but will shift off of it if the player moves away from it. I want this because it will make the game a bit easier for the player, thus less likely to frustrate them when there is 20+ enemy's and he cant aim very accurately. I have no idea how to do this and was wondering if someone here could point me in the right direction.

Not sure if it is relevant but I am using ray casting to shoot.

You can use a left 4 dead style subtle aim assist where the aim becomes slower if it's in range of a target so that players spinning around to a target wont shoot past it.

To do this you need to constantly check if the ray cast is hitting a valid target and if so you need to reduce the aim movement by 25% or so, that way it doesn't feel like auto-aim / cheating and the player can still aim at something else with full control.

Something along the lines of:

var aimAssist = 0;
var range = 50.0;
var aimSpeed = 0.75;

function Update(){
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var hit : RaycastHit;
    if (collider.Raycast (ray, hit, range)) {
        //Debug.DrawLine (ray.origin, hit.point);
        if (hit.collider.tag == "target") {
            aimAssist = 1;
        } else {
            aimAssist = 0;
   // do your movement controls

For auto aim that drags the aim towards the target you can use one of the other answers.

Do you have some kind of manual targetting? if not, try to locate the nearest target in sight (using renderer.isVisible() in a loop would do the trick, I think) and just point your raycast to the target coordinates using a Transform.LookAt() object from the startpoint of the raycast and using the LookAt() rotation.

I'm sure there are more simple approaches to that, tell me if you think of a simpler solution, I'm curious about this ;P

In a sense, it sounds like instead of shooting out a thin ray, you really want to shoot out a 'tube'. In that case, one approach would be to send out a few more rays around the mouse pointer (maybe 4-8), effectively making the rays into a tube. Then if one of those rays hits something, take the closest one (they could hit different objects), and if it is a new object then snap the mouse pointer to it (don't re-snap immediately to the same object or else you won't be able to move your mouse off of it).