Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by jcjarvis · Apr 10, 2015 at 05:53 AM · cameramenupopuptower defense

Create a popup menu at specific location

I Have a tower defense game and when a tower is clicked I would like a circular menu with buttons to pop up centered on the tower. I have created a panel with the buttons on it but do not know how to make it appear where the tower isalt text

I have looked through the "Creating UI elements from scripting" page but cant figure it out on my own. I know you can enable and disable menus and that is the most common way to make a popup menu but I need it to appear where the tower is and be moved whenever you click a different tower. I am using JS. Any help would be greatly appreciated.

menu.jpg (113.9 kB)
Comment
Add comment · Show 1
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 alphasystech · Nov 27, 2015 at 07:06 PM 0
Share

Hey, I am just wondering if you found a solution to implement that feature.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AlwaysSunny · Apr 09, 2015 at 08:47 PM

For such a thing, it would make sense to have only one instance of this group-of-controls, and move it around / activate it as needed.

How you will go about positioning the object relative to a world space coordinate depends upon the game's nature and the canvas projection settings.

If it's a world-space canvas, you might be able to simply give the group-of-controls the tower's world-space position coordinate. Otherwise, you'll need to translate the world space tower position coordinates into canvas space. See:

http://docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.html

http://docs.unity3d.com/ScriptReference/Canvas.html

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
avatar image
0

Answer by Foo-Byte · Nov 29, 2015 at 09:56 AM

I have a radial menu that I pop up when the player right-clicks. The biggest difference, I think, is that I use the Input.mousePosition to get the screen coordinates, whereas you'd have to use WorldToScreenPoint to get the screen position of your tower, as @AlwaysSunny mentioned.

To make it work, I created an empty that contains my handler script (the one that makes the pop-up appear, checks for the cursor moving away, and hiding the menu again).

This empty has a Canvas as a child, in Screen Space - Overlay mode, with appropriate scaling, etc. In this canvas, centered around (0,0), I created the radial menu, icons, buttons with callbacks, etc. The empty starts life as not active.

When I want to show the pop-up, I call a`ShowRadial` method in the hander, and pass in the 2D position that I want the menu to appear. Within the method, I do a simple gameObject.transform.position = new Vector2(x, y) and then gameObject.SetActive(true). This moves it to the position I want, shows the menu, and activates the buttons. Note: I do some math to prevent the menu going too close to the screen edge and being cut off, otherwise I would just set the position to the Vector2 screen space instead of creating a new one.

To hide the menu again, I just call gameObject.SetActive(false) within the Dismiss method.

Thinking about it, it would probably also work well to leave the empty at its origin, and move the main menu panel inside the canvas, rather than moving the empty.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

VR popup menu in front of Camera in Fixed Position/Rotation 2 Answers

Any tips on making a nice menu? 1 Answer

If using a conditional-situational menu, such as a pop-up, must wait till next OnGUI? 2 Answers

Halt function midway until player presses 'OK' then continue 1 Answer

how to show cursor on specific time? 2 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