get the mouse cursor position x and y and make gui follow on trigger

basically i want to make it so if i click GUI.Button it trigger it on and the GUI.Button x and y will follow cursor on the screen tell i click GUI.Button again triggering it off i know how make the trigger and set the x and y but i don’t know how to get the cursor position on the screen so it change x and y of GUI.Button to the cursor x and y coordinates on the screen

i need the code in C# other wise wont work with my other codes please help

Warning I don’t use c# this is JavaScript translated to C# by a C#-noob :wink:

You should make some variables that would regulate wheter or not the button is following, and the x,y position of the button:

public bool buttonFollow;
public Vector2 buttonPos;

And then make the button toggle the buttonFollow variable:

if( GUI.Button(Rect(buttonPos.x, buttonPos.y, 100, 100), "Your Button Text")){
buttonFollow = !buttonFollow;

And then to make the button actually change its position:

if( buttonFollow){
buttonPos = Event.current.mousePosition;

Please try to understand what these lines of code do and mean :slight_smile:
Don’t just copy-paste them and accept that they work, you won’t learn anything that way :wink:

But you must of course do as you like.

Good luck!