Show panel at mouse position

I have a box and after I hover that box, I want a panel to be shown (or instanciated) at the position of the mouse pointer…

I tried to look up on the internet for solutions, and I found this

and this

I want the action to happen as in the picture in attachments. Can someone help me?

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

1 Like

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. :slight_smile:
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).

1 Like