• 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
Question by Tohron · Dec 19, 2014 at 08:58 PM · button4.6

[Kinda Solved] Changing the Selectable Area of a Button

My goal is to have an invisible button positioned in front of a bunch of visible icons that do various animations when the button is pressed. However, I'm running into a problem: the area of the button that can actually be selected is smaller than the total area of the button object, and if the button is too small, none of the area is selectable.

This problem is particularly pronounced due to the fact that I've shrunk everything to 5% of its original size to improve performance for some of the really large objects in my game.

Thus, I'm wondering how one goes about changing the button area that can actually be selected? Ideally I'd want the entire rect transform area the button uses to be selectable.

Edit: After further debugging, it seems that the problem was that the button was being displayed using a UI camera, but the clicks were being registered based on whether the mouse was over the object's position from the perspective of the main camera. So now I have to figure out how to trigger buttons from a secondary camera.

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by NekitB · Dec 19, 2014 at 09:33 PM

If I correctly understand the task, I would probably use the new UI system, create a Canvas, then optionally a Panel as a child and then a Button object as a child of the panel. And then parent images to a Button so you can control the size of the button and the children will always be within the bounds of the button.

Optionally you can also add Horizontal Layout to the Button object so the images will proportionally fill the space, and also you can control padding between them and offset around them.

Then you can either add on click event to the button in its inspector sending messages to animator controller

Please see screen shot for details

http://prntscr.com/5iq05v

Comment

People who like this

0 Show 1 · 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 Tohron · Dec 19, 2014 at 10:01 PM 1
Share

I'm not sure you understand the problem.

The issue I have is that the button has a 2x2 area, but if the cursor is in the lower half of the button area, it doesn't highlight or register clicks. Meanwhile (as I just discovered), if the cursor is above the center of the button, off a bit to the left or right of the button, it does highlight and register clicks.

So in short, the problem is that the area that registers clicks seems to be different than what is defined by the button's Rect Transform. I want them to be the same.

avatar image

Answer by seru117 · Dec 30, 2015 at 04:49 AM

The easiest way I found was just to make the button a child of an image allowing you to resize the button without resizing the image.

If you just want to make the selectable area bigger add text as a child of the button.

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

28 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

Related Questions

How do I create a button that toggles with the 4.6 UI? 6 Answers

4.6 UI How to apply OnClick handler for button generated at runtime (script)? 0 Answers

Transition for buttons do not work before interaction 0 Answers

(4.6 UI) How to set up a window with x buttons, with a scroll bar? 1 Answer

Unity 4.6 GUI weird toggle+button interaction? 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