Cannot convert 'float' to 'UnityEngine.Vector3' - How to solve?

I have written a script that will perform a raycast whenever the left mouse button is pressed, and am now trying to make the camera move to the object that was hit by the raycast. Here’s the script I’m using for it:

var layerMask = 1 << 8;
var smooth : float = 5;

function Start () {


function Update () {
	// Cast a ray from the camera when LMB is pressed
	if (Input.GetMouseButtonDown(0)) {
		var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		var hit : RaycastHit;
		// Check for collision in 'Planets' layer
		if (Physics.Raycast (ray, hit, Mathf.Infinity, layerMask)) {
			print ("Ray hit an object!");
			print (hit.transform);
		var target = hit.collider.GetComponent(Transform);
		if (hit.collider.gameObject.tag == "Planet1") {
			transform.position = Mathf.Lerp(transform.position.x, target.position.x, Time.deltaTime * smooth);
			transform.position = Mathf.Lerp(transform.position.y, target.position.y, Time.deltaTime * smooth);
			transform.position = Mathf.Lerp(transform.position.z, target.position.z, Time.deltaTime * smooth);


Unity is giving me the error 'Cannot convert ‘float’ to ‘UnityEngine.Vector3’ on the lines where I’m using Mathf.Lerp. How would I fix this?

The way you are doing it you would need to put a line for each of .x, .y and .z:

transform.position.x = Mathf.Lerp(... etc

But fortunately you can do it in a single line with

transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime * smooth);