How to make a cube follow my mouse pointer?

How to make a cube follow my mouse pointer where ever i move it?

You could use RaycastHit and then transform the cube’s position according to where the Raycast hits.

C# script example would be as following:

using UnityEngine;
using System.Collections;

public class RaycastMoveCube : MonoBehaviour
    public Camera camToUse;
    public Transform CubeToTransform;

    // Update is called once per frame
    void Update()

            Ray ray;
            RaycastHit hit;
            ray = camToUse.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 100.0f))

                CubeToTransform.transform.position = hit.point;


This script has a max range of 100 but you can change that.
Example : Physics.Raycast(ray, out hit, 500.0f)