Adding AnimatorController by Script and LookAt

Hi Guys, i would like to know how i can add a Animator Controller to a character using a Script. This is important as my characters will be generated during the runtime. I also have the problem that my persons do not look in the walking direction when using an animation, but they do without.

I really appreciate any help.

Here the code i am using for my second problem:

        Animator animator = GetComponent<Animator>();

        if (animator)
        {
            Vector3 moveDirection = waypoints[targetwaypoint] - transform.position;
            moveDirection = 1f * moveDirection.normalized;

            moveDirection.y -= 20f * Time.deltaTime;
            transform.LookAt(moveDirection, Vector3.up);
            controller.Move(moveDirection * Time.deltaTime);

            if (Vector3.Distance(transform.position, waypoints[targetwaypoint]) <= waypointRadius)
            {
                targetwaypoint++;
                if (targetwaypoint > waypoints.Length - 1)
                {
                    targetwaypoint = 0; //looping around
                }
            }
        }

In Unity 4.1, you can set the AnimatorController at runtime.

For the look direction problem, play around with the import settings on your animation. You may need to check Bake Into Pose or change Based Upon to Original. If you need to control the head and you have Unity Pro, then in OnAnimatorIK() call SetLookAtPosition() and SetLookAtWeight(). If you don’t have Pro, configure your avatar so it doesn’t control the head (i.e., set the head bones to None) and use the legacy HeadLookController: http://u3d.as/content/unity-technologies/head-look-controller/1qN