You could place a panel over your screen, make it transparent and add an event trigger to it. You could then get the mouse position when you click via OnMouseDown
Thanks for helping, but I would like to hesitate using the onmousedown() function because I only want to get the mouse position when the panel/button is hovered
Look into the interface(s) OnPointerEnter/Exit.
If this is on a Canvas, you probably already have an eventsystem in the scene (gets added with the canvas, check that it’s there…)
If it’s not on the canvas, or you don’t have a canvas, you can add an EventSystem in the scene, and separately - a Raycaster2D on your camera. If you run the game, and select the EventSystem , it should show your mouse enter/exit events there…
Then, you just add the interface(s) that I mentioned above, and put the code you want to execute in a script on the object(s).