How to make object solid with Vector3.MoveTowards?

I have a sphere which moves to my mouse position when I click on the screen. I also have a cube, now I can move trough the cube, but I want the cube is solid so I can`t move trough it. This is my code:

public bool canMove = false;
public Vector3 endPoint;
public float duration = 50f;
void Update(){
  if(Input.GetMouseButton(0)){
    canMove = true;
    endPoint = Input.mousePosition;
    endPoint.z = transform.position.z = Camera.main.transform.position.z;
    endPoint = Camera.main.ScreenToWorldPoint(endPoint);
  }
  if(transform.position == endPoint){
    canMove = false;
  }else if (canMove){
    transform.position = Vector3.MoveTowards(transform.position, endPoint, duration * Time.deltaTime);
  }
}

How can I make the cubes solid so I can`t move trough it?

Sorry for bad formulated question.

Proud would probably have to add a rigid body and collides to make it so that the two are solid objects, and use addforce or set the rigid body velocity in order to mov the objects.