How can i make that it will create cubes at mouse position even if i move the mouse fast ?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawLinesWithMouse : MonoBehaviour
{
    public GameObject objectToDraw;

    private List<Vector3> pointsList;

    // Use this for initialization
    void Start()
    {
        pointsList = new List<Vector3>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            RaycastHit hit;
            Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 1000))
            {
                Vector3 hitpoint = hit.point;
                pointsList.Add(hitpoint);

                GameObject go = Instantiate(objectToDraw);
                go.transform.position = hitpoint;

                print(hitpoint);
            }
        }
    }
}

If i move the mouse slow very slow it will Instantiate the cubes each one close to the other but once i move the mouse faster and faster there will be more spaces/distances between the cubes.
How can i make that there will be no spaces/distances between the Instantiated cubes even if i move the mouse very fast ?

This is an issue with the delta time of the update. (It’s too low for your purposes).

You have multiple options:

  1. Lower the FixedDeltaTime in Time settings;
  2. Create a Coroutine to use instead of the update which wait less that the DeltaTime;
  3. Create a Vector3 which Lerps from the first mouse position to the last, respecting the DeltaTime. So basically you will move the mouse pretty fast, the Vector3 is still going to be back there feeding the space with the cubes you want until it reachs it’s position. The only thing that you will need to check and calculate is the alpha of the lerp (Velocity) based on your DeltaTime. And probably this is going to have a problem if you don’t follow a straight line. You would have to store all the points and go lerping from one to another one;
  4. If you’re simple trying to draw lines with the mouse and nothing special, I would say to you try a different approach, maybe with LineRenderer ou GL.Lines;