Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by laradov · Dec 02, 2015 at 08:03 PM · uiguibuttonmenupanel

In game right click menu

Hi,

I want to create an in-game right click menu. I want it to look like Windows right click menu. Also the buttons in the menu must be dynamically created since the menu will change with respect to clicked object. I tried using panels and instantiating button prefabs under it but I couldn't place it in the desired position (top left of the menu must be on the mouse position). Any suggestions or tutorials?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessespike · Dec 02, 2015 at 09:20 PM 0
Share

What's the problem with positioning the menu with the mouse position? Try changing the pivot or parenting the menu to a game object.

There are plenty of tutorials. If you're looking for one that specifically addresses your problem, then probably no. UI Canvas tutorial talks about positioning, that might help if you haven't watched it already.

avatar image laradov Jessespike · Dec 03, 2015 at 08:38 AM 0
Share

I know these tutorials, they are basics but they didn't help. The problem with positioning is, top left of the menu must be on the mouse position. Pivoting and parenting didn't work or I couldn't make it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by killerstreak · Dec 03, 2015 at 10:45 AM

There are many ways you could do this really, but basically you could just get the position of the mouse with something like; Input.mousePosition. Then use that position to well, position whatever you want the menu to be made out of.

I suggest you could try creating the menu dynamically with for example Ongui(); You should look into those (especially because they are very easily manipulated by script and therefore viable in loads of situations).

Not actual working code just demonstrating what I mean, e.g.


var mousepos = Input.mousePosition;

GUI.Button(new Rect(mousepos.x (+25*), mousepos.y (-15*), 50, 30), "Click") ;

//*Note, I am not sure if the x and y coordinates are the center of the box, or the top left corner, but if they are you should add and substract 25px and 15px from the mousepose respectively, which is simply half the width and length of the box. If that is not the case then don't do that.


this will create a button that is 50px by 30px with the text Click in it. The corners located at the position of the mouse. I could go into more detail how all that works, but really, you can figure that out yourself, good luck! :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Button onClick events will not be triggered 1 Answer

Button highlighted a pushable without touching it 0 Answers

How to use options in the Dropdown menu UI? 2 Answers

Menu button in game isn't working 0 Answers

Help With Adding Buttons To Panel 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges