How to make 3D object become the cursor?

I want the regular arrow cursor to be used for the majority of my game. However, when the user clicks on a button called “draw”, I want the cursor to change from the arrow to a 3d pencil object I created. I then want it to draw on the blank panel wherever the user moves the mouse as clicked (like in paint or photoshop).

I think I could put a camera pointing at the 3D pencil and then create a raw image for that camera. Then, you can add the plain image to the canvas, hide the mouse with Cursor.visible = false and have it follow the X and Y of the mouse. Answer if it worked or not!

(If you don’t know what is a Raw Image, then search in the unity documentation).

User the Cursor.visible flag to hide the cursor in your script (Unity - Scripting API: Cursor.visible )

Then create a script on the 3D object that moves its position in the Update method to the mouse cursor position. You can get your mouse position by transforming the screen position to world coordinates (see here: Unity - Scripting API: Camera.ScreenToWorldPoint).

Should look something like this:

void Update(){
	Vector3 worldPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y, Camera.main.nearClipPlane));
	transform.position = worldPosition;
}