Instantiate UI element at mouse position but element shouldn't keep following mouse

Hi,

As stated above, I’m trying to initialize a UI element at the current mouse position. I’m using the code below to position a panel at mouse position. The problem is, after initialization, the panel keeps following the mouse, making it impossible to click on. How do I initialize it at clicked position but then have it stay in place?

Thanks a lot

Example code:
float x = Input.mousePosition.x;
float y = Input.mousePosition.y;
Vector3 mousePosition = new Vector3(x + 20, y - 40,0);
_inspectionPanel.transform.position = mousePosition;

Hi,

Perhaps a Stupid response but you shouldn’t do that in update() method.

I am thinking the same thing; that that code might be inside update & that explains the behaviour.
Instantiate the panel and set its position on your click, that’s it. It’s done :slight_smile: