Move GUITexture with mouse

I know this is a very easy question.

This is my code when mouse is down:

transform.position = new Vector3(0.5f,(Input.mousePosition.y / Screen.height), 3);

I’m using transform.position to move the GUITexture. However, my problem is that whenever I select/click the GUITexture, it moves directly to the mouse position. How can I make it not move when I click it? Please let me know if this is bad explained.

You did not share the rest of your code, so I have to guess a bit. You are likely executing the line of code in your question in OnMouseDrag(). The ‘trick’ is to capture the offset between the mouse and your object when the mouse goes button goes down. If you are using OnMouseDrag(), then do it in OnMouseDown(). If you are using Input.GetMouseButton(), then do it in Input.GetMouseButtonDown(). You calculate the pixel offset from your mouse position to the screen coordinate of your GUI.Texture.

 Vector3 offset = Camera.main.ViewportToScreenPoint(transform.position) - Input.mousePosition;

You will add this offset to Input.mousePosition and use the result in your line of code above.

It seems this person nearly has the same question. You could use the code in the answer: