Say i have the following wheel:

enter image description here

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


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.

  • 2
    \$\begingroup\$ 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? \$\endgroup\$ – DMGregory Jul 22 '19 at 22:39
  • \$\begingroup\$ 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. \$\endgroup\$ – 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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.