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
3
Question by Renaldo-Goosen · Apr 20, 2015 at 12:05 AM · guibuttoncanvasifselected

If button highlighted

Hi there,

My question is a short one. I've been looking for a reference on a Canvas selectable button. The button itself does not call a function when clicked, it should just wait to see if it has been highlighted.

I have a script that was put directly on the button itself but I do not know how to write an "if statement" on "if this button is selected then.." in C#.

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 Orr10c · Dec 28, 2016 at 11:17 AM 0
Share

and if i want to know when its not highlighted?

2 Replies

· Add your reply
  • Sort: 
avatar image
14
Best Answer

Answer by DoTA_KAMIKADzE · Apr 20, 2015 at 12:07 AM

Add script containing this code to your Button:

 using UnityEngine;
 using UnityEngine.Events;
 using UnityEngine.EventSystems;
 
 public class YourScript : MonoBehaviour, IPointerEnterHandler, ISelectHandler
  {
      public void OnPointerEnter(PointerEventData eventData)
      {
          //do your stuff when highlighted
      }
      public void OnSelect(BaseEventData eventData)
      {
          //do your stuff when selected
      }
  }
Comment
Add comment · Show 4 · 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 Renaldo-Goosen · Apr 20, 2015 at 03:07 AM 0
Share

Thank you very much it seemed to work using the mouse.. Though I do have one issue.

When I select the button using the navigation on the keyboard, it does not read as being highlighted because a pointer is not being used.

How would I go about reading if it is highlighted even without pointer?

avatar image DoTA_KAMIKADzE · Apr 20, 2015 at 01:53 PM 0
Share

Updated my answer, check it out.

avatar image Orr10c · Dec 28, 2016 at 11:17 AM 0
Share

and if i want to know when its not highlighted?

avatar image literallydeath Orr10c · Dec 29, 2016 at 06:07 AM 1
Share

Use OnPointerExit or OnDeselect for that. The EventTrigger article lists the various events you can intercept.

avatar image
3

Answer by sisse008 · Apr 29, 2018 at 01:04 PM

cant find any new info on this topic. OnPointerEnter() only works with the mouse.

How can I check if a button is highlighted while using keyboard navigation?

thank you

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

6 People are following this question.

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

Related Questions

creating a label from a button click 1 Answer

How to make button stay the same size on all screens? 2 Answers

Can't enable canvas 1 Answer

How to instantiate a prefab between Canvas and a Button? 0 Answers

On Click paramaters disappear from button prefab? 5 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