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
0
Question by OfficerNumberOne · May 24, 2019 at 07:38 PM · event triggeringpointertooltip

Using Event Trigger from Script to access PointerEnter and PointerExit

I am trying to use Event Trigger to access PointerEnter and PointerExit from script. I am trying to create Tool Tips, but I only want the Tool Tips to display if the Button the mouse hovers over is interactable = false.


I can get this to work by dragging and dropping the correct GameObject into the Inspector, but this method does not know whether the button the mouse is over is interactable or not; therefore it always displays the Tool Tip.


Hopefully this makes sense if not I can try and explain better. Thanks!

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

2 Replies

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

Answer by Zankomag · May 25, 2019 at 01:24 AM

You don't need EventTrigger for accessing PointerEnter and PointerExit through script (you can do it via EventTrigger though). All you need is EventSystem on scene and implementing required interfaces:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class ToolTips : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
 {
     Button button;
 
     private void Awake() {
         button = GetComponent<Button>();
     }
 
     public void OnPointerEnter(PointerEventData eventData) {
         if (!button.interactable)
             ShowToolTips();
     }
     public void OnPointerExit(PointerEventData eventData) {
         if (!button.interactable)
             HideToolTips();
     }
 }

Also if you need only Interactable feature and don't need Button.onClick, you can just use Selectable component instead of Button

Comment
Add comment · 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 OfficerNumberOne · May 27, 2019 at 03:12 PM 0
Share

This method does work; however, I decided to simply use the EventTrigger system in the Inspector on each UI Element. I was able to get the ToolTips to not display by disabling Raycast Target through script:


button.GetComponet-Image-().raycastTarget = false;

avatar image
0

Answer by OfficerNumberOne · May 25, 2019 at 03:28 AM

@Zankomag, thanks for the help, not sure if its working yet. Using TextMeshPro, can use use TextReference.text = "words" to change the text in game?


Right now I have this (Ive implemented everything else you said):

public TextMeshProUGUI toolTipT;

public void OnPointerEnter(PointerEventData eventData) {

if (Button.interactable) { toolTipT.text = "WORDS"; }
}


Does the toolTipT.text need to be in the Update method?

Comment
Add comment · Show 2 · 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 Zankomag · May 25, 2019 at 09:13 AM 0
Share
  1. Sure, you should change Text$$anonymous$$eshPro text through its reference.

  2. No, it doesn't in this case.

avatar image OfficerNumberOne Zankomag · May 25, 2019 at 09:35 PM 0
Share

Thanks, I had to turn Raycast Target off for certain UI elements I didnt want to mouse over. However, is there a way to differentiate between which button the mouse is over. Cause right now all the inactive buttons display the same message. I could solve this with booleans, but it would be alot of extra code and was wondering if there was an easier way.

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

108 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 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 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

Can I set a specific Pointer for the EventTrigger on Buttons for example? 0 Answers

Creating a Tooltip when hovering over a UI Button? 3 Answers

Pointer Down event on a button still registering a hold even when I drag pointer away?? 1 Answer

EventTrigger runtime added callbacks to OnPointerClick/OnPointerUp/OnPointerDown don't work. 1 Answer

Touchscreen Joystick Character Control using PointerEventData 1 Answer


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