Using Input.mousePosition to move panel to mouse position. Only works properly first time
Hello,
I'm using Input.MousePosition to move a panel to the position of the mouse like so:
Vector2 pos = new Vector2(Input.mousePosition.x + (inventory.optionsMenuRect.rect.width / 2) + 2, Input.mousePosition.y);
inventory.optionsMenu.transform.position = pos;
How this occurs is I click on an item within my inventory the window is moved to the position of the mouse and then set active. When the mouse leaves the window it will go back to being inactive. Everything works fine the second time. However, when I try to do it any number of consecutive times sometimes the window will stay in the previous positions, the buttons inside the panel will not work anymore and the window will move but just not to the correct place.
Any idea why this is happening?
Answer by Hannibal196 · Oct 12, 2017 at 09:47 PM
I don't know what was initially causing the issue. However, I have fixed it. The solution for me was moving the window out of view by setting up a preset Transform where the window would be when it's not needed. When it's needed it is then moved to the MousePosition.
Your answer
Follow this Question
Related Questions
UnityEngine.UI and UnityEngine.EventSystem do not work, what do I do? 1 Answer
Desktop and VR Event System? 0 Answers
Making UI block rays with touch inputs 0 Answers
Namespce Error!!!!!!!!! 0 Answers
Event not being invoked 2 Answers