Problem with converting RaycastHit to Vector3

Hi, when I used this code:
using UnityEngine;
using System.Collections;

public class Mousetargeting : MonoBehaviour
{
	void Update ()
	{
		if(Input.GetMouseButtonDown(1))
		{
			RaycastHit mouseHit;

			if(Physics.Raycast (Camera.main.transform.position,Input.mousePosition, out mouseHit))
			{
				transform.position = mouseHit.point;
			}
		}
	}
}

I get the error, "error CS0029: Cannot implicitly convert type ‘UnityEngine.RaycastHit’ to ‘UnityEngine.Vector3’

I’m trying to move the object that this code is in to the point where the mouse is whenever I right click on the screen. Why can’t RaycastHit be recorded as a Vector3?

There is a coordinate system for camera, world and terrain. In essence your missing the conversion. The example below goes a step further and shows one way to use a layer mask for filtering out specific layers, but you can comment that out. I simplified this from what I am using for a better example.

        public static Vector3 GetRealCords()
        {
            /// <summary>
            /// Translate current Mouse X/Y into realworld cords using raycast
            /// </summary>
            /// <returns>Vector3 realworld cords (0,0,0) for invalid queries</returns>
            /// 

            Ray xray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;

            int mask = 0;
            mask |= (1 << LayerMask.NameToLayer("Building"));
            mask |= (1 << LayerMask.NameToLayer("Trees"));
            mask |= (1 << LayerMask.NameToLayer("nodes"));
            mask |= (1 << LayerMask.NameToLayer("Ignore Raycast"));
            mask = ~mask;


            if (Physics.Raycast(xray, out hit, 1000, mask))
            {
                if (hit.collider.gameObject.name == "Terrain")
                {

                    return hit.point;
                }

            }

            return Vector3.zero;
        }

If you want to extract the “impact point in world space where the ray hit the collider”, in other words, the vector3 you expect from your raycast hit. Then you need to get the “point” variable of the RaycastHit class

RaycastHit mouseHit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

if (Physics.Raycast(ray, out mouseHit, 100)) 
{
    transform.position = mouseHit.point;
}

For more info about raycasting, read the Unity Script Reference at Unity - Scripting API: RaycastHit