Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 adamt · Jul 29, 2015 at 10:56 PM · uiraycastcollider

Scrollable, clickable overworld map

I'm trying to implement a scrollable overworld map that will also accept mouse clicks. I have a map game object whose size is larger than the viewport of my device. That game object has Unity's ScrollRect component attached to it, to handle the scrollable layer (the scrolling is clamped, but it can be scrolled in any direction).

Underneath this game object is the object to be scrolled (a single Image script), and a few "zones" that should be clickable to travel to those zones in the game.

To give you an idea of the game object hierarchy, it looks like this:

 Main Camera (Physics2DRaycaster)
 ui_root (Canvas, GraphicsRaycaster)
   map (ScrollRect)
     map_image (Image)
       zones (empty)
         forest (PolygonCollider2D, ZoneClickHandler)
           title (Text)
         cave (PolygonCollider2D, ZoneClickHandler)
           title (Text)

The tricky part here comes from the fact that the zones aren't simply rectangular areas, so I can't use Unity's default Button component to check if a zone has been clicked; the zones on the map are actually concave polygons. To get around this, I implemented each zone's root game object as a 2D polygon collider with a custom script to implement IPointerClickEvent when the collider is clicked.

I should also note that each zone is not its own sprite. I've seen similar implementations that check the alpha channel on a sprite using a custom ICanvasRaycastFilter, but that won't work here since the map is a single sprite, and I'm simply defining clickable regions on that sprite.

Unfortunately, this approach doesn't seem to be working correctly (sorry for burying the lede, but I'm sure you already realized this!). In fact, what happens is that my ZoneClickHandler#OnPointerClick method is only fired when the mouse is clicked over the "title" game object's RectTransform, inside each zone (which is much smaller than its containing zone game object and polygon collider, and rectangular). I have no idea why that would be the case, since the ZoneClickHandler component is attached to the zone game object itself, not its child "title" game object.

I wouldn't mind hearing approaches that are both inline and not inline (e.g., throwing out the idea that I can mix-and-match UI- and non-UI-related objects) with the way I'm trying to get this going.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Allow Click Through some UI Elements 1 Answer

Make "polygon" collider for UI element 4 Answers

Blocking and not blocking input in new uGUI 4.6 1 Answer

Collider Blocking Worldspace Canvas? 1 Answer

Detect only UI button click 3 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