How to use the LookAt function

How would I use the LookAt function? For example, I have a character that I control by clicking on a specific point on the ground. I have selection and walking working (sort of), but I have two problems. First up: I'm using the LookAt function to look at a point at the ground and then walk over there. However, the LookAt doesn't work in reverse. If I click behind the unit, it won't turn around. Second, I would like to stop it from rotating up and down, so the head is always horizontal to the ground. Here's my script currently. The variables referenced are in another script that gets the mouse input.

var MouseClick : MouseClick;
var speed = 2;

function unitSelection () {
    MouseClick.selected = true; 
    Debug.Log ("I'm selected. What can I do for you?");

function Update() {
    if (MouseClick.move) {      
        transform.Translate(Vector3.forward * Time.deltaTime * speed);

How can I make this happen?

EDIT: Here lies the MouseClick script:

var selected = false;
var move = false;
var TargetDestination;

function Update () {
    if (Input.GetButtonDown ("Fire1")) {
        var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        var hit : RaycastHit;
        if (Physics.Raycast (ray, hit)) {
            if (hit.collider.tag == "Unit") {
                    hit.collider.SendMessageUpwards ("unitSelection");

            else if (hit.collider.tag == "Terrain") {
                Debug.Log ("You Missed!");

    if (selected && Input.GetButtonDown ("Fire1")) {        
        var ray1 = Camera.main.ScreenPointToRay (Input.mousePosition);
        var hit1 : RaycastHit;
        if (Physics.Raycast (ray1, hit1)) {
            if (hit1.collider.tag == "Unit") {
                    Debug.Log ("I'm already selected!");
            else if (hit1.collider.tag == "Terrain") {
                selected = false;
                Debug.Log ("You unselected!");

    if (Input.GetButtonDown ("Fire2") && selected) {
        var ray2 = Camera.main.ScreenPointToRay (Input.mousePosition);
        var hit2 : RaycastHit;

        if (Physics.Raycast (ray2, hit2)) {
            if (hit2.collider.tag == "Unit") {
                    Debug.Log ("I'm already selected!");
            else if (hit2.collider.tag == "Terrain") {
                Debug.Log ("I'm going already!");
                move = true;
                TargetDestination = Input.mousePosition;                

Thanks in advance - Elliot Bonneville.

Well, "LookAt" itself does work in any direction, so I'm guessing your problem probably lies somwehere in your "MouseClick" class. Perhaps it doesn't contain the values that you think it does.

Since "MouseClick" seems to be your own custom class, and you don't show the code which populates its "TargetDestination" variable, it's difficult to guess any further about where the problem lies.

However, the second part of your question - how to stop it from looking up or down and instead have it look parallel to the ground - is relatively straightforward.

First, put your target "LookAt" position into a Vector3 variable, then set the y component of that Vector3 variable to the character's own Y value. You then have a target which differs only in the X and Z plane. Eg:

var lookTarget = MouseClick.TargetDestination;
lookTarget.y = transform.position.y;

hope this helps!

Hah! Got it. Apparently, I put the mouse's screen coordinates in MouseClick.TargetDestination, when I actually needed the mouse's ray coordinates. Now it works! Yay.