Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by TheKillerbros · May 11, 2019 at 06:52 PM · textbutton trigger eventsevent triggeringpointerobject reference

Refrence another text object from within a script involving PointerEnter and PointerExit

So I've checked around and normally I'm able to find this stuff, or find a work around.
For reference-
I have 3 UI objects, one is a button called "Up Kills", and its subsequent text "Upkilltext"
The other object is a text object named "Hahlol".

Up Kills has an EventTrigger script attached to it.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;    
 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class UpgradeKillButton : EventTrigger {
 
     //Text UpInfo = GameObject.Find("Hahlol").GetComponent[UnityEngine.UI.Text](); ??????
 
     public override void OnPointerEnter(PointerEventData data)
     {
         UpInfo.text = ("Lol JK it does nothing");
     }
 
     public override void OnPointerExit(PointerEventData data)
     {
         UpInfo.text = ("");
     }
     
 }

The commented line is the one I'm having trouble with.
Usually I just use a [SerializeField] and call it a day, (Just learning here, expecting to find a better way later.)
But that wont show up in the Inspector.

So what I'm attempting to do, is change the text of "Hahlol" whenever the mouse has entered the button, and upon leaving, remove the text.
Not looking for a copy-paste answer, if you can avoid it.
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

1 Reply

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

Answer by Hellium · May 11, 2019 at 07:35 PM

Remove the EventTrigger component attached to your button, and change the script as follow:

 using System.Collections;
  using System.Collections.Generic;
  using UnityEngine.UI;    
  using UnityEngine;
  using UnityEngine.EventSystems;
  
  public class UpgradeKillButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  {
       [SerializeField]
       private Text UpInfo ;
  
      public void OnPointerEnter(PointerEventData data)
      {
          UpInfo.text = "It works now!";
      }
  
      public void OnPointerExit(PointerEventData data)
      {
          UpInfo.text = null;
      }
  }

Make sure you have an EventSystem component attached to a gameObject in your hierarchy.

Comment
Add comment · Show 3 · 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 TheKillerbros · May 11, 2019 at 08:38 PM 0
Share

Tried all different methods of making this work, I added a second event system, just to see if i needed it (nope.), with each change I'm getting this error: alt text

I tried setting it up using IPointerEnterHandler before using this as refrence: https://docs.unity3d.com/ScriptReference/EventSystems.IPointerEnterHandler.html Though i think i was getting a different error when doing that, so, on the right track, maybe.

hell.png (5.0 kB)
avatar image Hellium TheKillerbros · May 11, 2019 at 09:03 PM 0
Share

$$anonymous$$y bad, remove the override keyword.

avatar image TheKillerbros Hellium · May 11, 2019 at 09:12 PM 0
Share

Thanks alot!

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

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

What is the best way to search a text clock UI for certain times 0 Answers

[Help] Event Trigger buttons not working? 1 Answer

Triggering UI button onmousedown, without waiting for mouseup event? 1 Answer

Change TMP text color through event trigger 0 Answers

Dialogue not displaying next sentence 0 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