- Home /
Duplicate Question
Mouse position on 4.6 Canvas
Hello, I want to get mouse position on my canvas (Render mode Overlay) . So when i press right mouse button, i want to get mouse position on canvas, and change panel position to mouse position. Currently using this code, but it doesnt work:
Vector2 screenPos = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
Vector3 convertedGUIPos = new Vector3 (GUIUtility.ScreenToGUIPoint (screenPos).x, GUIUtility.ScreenToGUIPoint (screenPos).y, 0f);
clickPanel.GetComponent<RectTransform> ().position = convertedGUIPos;
Looking at this, with all due respect and admiration for moderators, I don't believe your link is an adequate response to this particular question...
What I get from this question is very different than your suggested answer. The poster is looking for code to match position of a UI element to the mouse pointer. which entails getting the pointer coordinates AND the methods required to translate that position accurately to the overlay/camera screen space (etc) AND how to move that UI element accordingly.
Please correct me if Im wrong, but Im thinking the screen to world space is not what the poster is looking for. I say this because I need the EXACT same functionality requested here... and I havent found it ... not in your reference links either.
So, can we have an opportunity to get a situation specific answer .... ins$$anonymous$$d of a general use series of link trails? Please reopen the question.
Follow this Question
Related Questions
Is There An OnMouseStop? 0 Answers
Convert Mouse Position - To Transform 1 Answer
Lock mouse position with a Rect, possible? 1 Answer
Rotating object towards mouse point 1 Answer
Instantiating Object On Map 1 Answer