# Unity Mouse position for weapon wheel

Say i have the following wheel:

Now i wish to use the mouse to select weapon by movement:

So

If mouse is to the left it picks the Sword if mouse is at the top it selects the bow and arrow if the mouse is in the bottom then it selects the hand

Since my game is not visually showing the mouse it has to be at any position. i

However, I am not quite sure how to do this? So I am hoping some of you might be able to help. I have looked at getting the mouse position as a vector 2 but I am unsure on how to get the correct position.

• In what way is the mouse position that you get "as a vector 2" not the correct position? How does it differ from the value you'd deem correct? – DMGregory Jul 22 '19 at 22:39
• I think breaking it down in steps will help. First you display the UI Wheel on mousedown then you get and store the Input.mousePosition at that point next you would check against the first position whether you are draggin up,down left or right to show the hovering effect of choice and then on mouseUp you would select the one you were on. – Justin Markwell Jul 23 '19 at 0:14

Here's my example: attach this script to the arrow button, fist button etc.

public class example : monobehavior {

void OnMouseOver()
{
//select weapon
}
}


For your problem of the mouse not being displayed, you could add a sprite to your canvas that is basically the boundary of the select area, and add the script to that. Then you could disable the sprite renderer so it doesn't show up in the game.

If you only wanted the weapon selected if the player had the mouse over it and released the key that brought the menu up, you could put your code in update (you may need to do this already) and add an if statement:

if(Input.GetKeyUp(your key choice))


to the OnMouseOver() function

You can do this mathematically:

Vector2 menuPosition = radialMenu.transform.position;  // Assumes the center of your menu
Vector2 mousePosition = Input.mousePosition;

• Keep in mind that transform.position gives you a position in world space, and Input.mousePosition gives you a position in screen space. These are not directly comparable without some additional work to get them into the same coordinate space. – DMGregory Apr 20 at 18:32