CS0246: The type or namespace name `targetPosition' could not be found. Are you missing a using directive or an assembly reference?

I found a js on the wiki that allow objects to move to the point where the mouse is clicked, like in rpg games. Trying to convert it to C# now but I've been stuck at the same problem for about an hour now and feel like I need some help, I'ld really appreciate it. :)

Here's the cs script at this point, (I add the js at the bottom aswell so you can have a look at it, since the js one is fully functional.) ` using UnityEngine; using System.Collections;

public class Controller : MonoBehaviour { public int speed = 3; private int targetPosition = Vector3;

void Update () 
{
    if(Input.GetKeyDown(KeyCode.Mouse0)){
        playerPlane = new Plane(Vector3.up, transform.position);
        ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        hitdist = 0.0;

        if (playerPlane.Raycast (ray, hitdist)) {
            targetPoint = ray.GetPoint(hitdist);
            targetPosition = ray.GetPoint(hitdist);

            targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
            transform.rotation = targetRotation;
        }
    }
    MoveTowards(targetPosition);
}

void MoveTowards (position Vector3) {
    direction = position - transform.position;  
    direction.y = 0;

    if (direction.magnitude < 0.5) {
        SendMessage("SetSpeed", 0.0);
        return;
    }

    // Modify speed so we slow down when we are not facing the target
    forward = transform.TransformDirection(Vector3.forward);
    speedModifier = Vector3.Dot(forward, direction.normalized);
    speedModifier = Mathf.Clamp01(speedModifier);

    // Move the character
    direction = forward * speed * speedModifier;
    GetComponent (CharacterController).SimpleMove(direction);

    SendMessage("SetSpeed", speed * speedModifier, SendMessageOptions.DontRequireReceiver);
}

}

`

<// JS VERSION BELOW*\*> ` var speed = 3;

private var targetPosition:Vector3;

function Update () { if(Input.GetKeyDown(KeyCode.Mouse0)) { var playerPlane = new Plane(Vector3.up, transform.position); var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hitdist = 0.0;

    if (playerPlane.Raycast (ray, hitdist)) 
    {
        var targetPoint = ray.GetPoint(hitdist);
        targetPosition = ray.GetPoint(hitdist);
        var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
        transform.rotation = targetRotation;
    }

}
    MoveTowards(targetPosition);

}

function MoveTowards (position : Vector3) { var direction = position - transform.position; direction.y = 0; if (direction.magnitude < 0.5) { SendMessage("SetSpeed", 0.0); return; }

// Rotate towards the target

// Modify speed so we slow down when we are not facing the target
var forward = transform.TransformDirection(Vector3.forward);
var speedModifier = Vector3.Dot(forward, direction.normalized);
speedModifier = Mathf.Clamp01(speedModifier);

// Move the character
direction = forward * speed * speedModifier;
GetComponent (CharacterController).SimpleMove(direction);

SendMessage("SetSpeed", speed * speedModifier, SendMessageOptions.DontRequireReceiver);

} `

Is the C# version you posted the complete one? I can't see where you declared 'targetPosition' and a bunch of other variables.

Cheers~!