Move with the mouse and create on click

Im need this for learning purposes and if some nice person could dedicate some of there time to show me how it can be done.
So basically what i would like todo is when i create a gui button and once i click on it.
It would spawn a object on terrain which follows the mouse until you place it down. Like in RTS games when your building houses.

Thank you to anyone who helps

In your script where the button is, add a public attribute in your class where you can put the prefab gameobject you want to spawn.
When the button is clicked spawn one and reference it in a private attribute of your class.
On the Update() function, if the private attribute is not null, cast a ray from the camera to the ground and move the private gameobject to the collision point.

When you want to place it down, just unreference the object.

I didn’t get into details, because I think some research of your own would have helped you. This is not complicated stuff… Or maybe I’m missing something in your demand.