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 /
avatar image
1
Question by Frenzy-Alex · Sep 09, 2015 at 09:39 AM · c#unity 5triggereventonmouseenter

EventTrigger PointerEnter

Hi Guys, I have problem with Pointer Event Trigger - Pointer Enter. I have created from script Text, i want to change text color when I touch it with the mouse. But when I touch it function OnPointerEnter was not called. Only when I click on the text it's change color..

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Events;
 using UnityEngine.EventSystems;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ComboBoxText : MonoBehaviour
 {
     public GameObject _current;
 
     public GameObject _go;
     public RectTransform _rt;
     public Text _text;
     public EventTrigger _et;
     public EventTrigger.TriggerEvent _trig;
     public EventTrigger.Entry _entry;
 
     public ComboBoxText(GameObject _current, Font _font, int _fontSize)
     {
 
         _go = new GameObject();
         _go.name = "Tested GameObject";
         _go.transform.parent = _current.transform;
 
         _go.AddComponent<RectTransform>();
         _rt = _go.GetComponent<RectTransform>();
         _rt.anchoredPosition3D = new Vector3(0f, 0f, 0f);
         _rt.pivot = new Vector2(0f, 1f);
         _rt.sizeDelta = new Vector2(130, 30);
         _rt.localPosition = new Vector3(0f, 0f, 0f);
         _rt.localScale = new Vector3(1f, 1f, 1f);
         _rt.anchoredPosition3D = new Vector3(0f, 0f, 0f);
         _rt.pivot = new Vector2(0f, 1f);
         _rt.localScale = new Vector3(1f, 1f, 1f);
 
         _go.AddComponent<Text>();
         _text = _go.GetComponent<Text>();
         _text.text = "TestText";
         _text.font = _font;
         _text.fontSize = _fontSize;
         _text.color = new Color32(200, 200, 200, 255);
         _text.alignment = TextAnchor.MiddleLeft;
 
         _et = _go.GetComponent<EventTrigger>();
         if (_et == null) { _et = _go.AddComponent<EventTrigger>(); }
         _trig = new EventTrigger.TriggerEvent();
         _trig.AddListener((data) => OnPointerEnter());
         _entry = new EventTrigger.Entry() { callback = _trig, eventID = EventTriggerType.PointerEnter };
         _et.delegates = new List<EventTrigger.Entry>();
         _et.delegates.Add(_entry);
     }
 
     public void OnPointerEnter()
     {
         Debug.Log("OnPointerEnter");
         _text.color = new Color32(200, 200, 200, 255);
     }
 }

Creating was called from another script:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Events;
 using UnityEngine.EventSystems;
 using System.Collections;
 using System.Collections.Generic;
 
 public class UI_ComboBox :
 {
     public GameObject _go;
     public Font _font;
     public int _fontSize;
 
     private RectTransform _rt;
     private ComboBoxText _mainText;    
 private uint _CurrentItemNum = 0;
 
     void Start () {
         _rt =  _go.GetComponent<RectTransform>();
 
         _mainText = new ComboBoxText(_go, _font, _fontSize);
         _mainText._go.name = _go.name + "_MainText";
         _mainText._rt.sizeDelta = new Vector2(_rt.sizeDelta.x, _rt.sizeDelta.y);
         _mainText._rt.anchoredPosition3D = new Vector3(0f, 0f, 0f);
         _mainText._text.text = " MainText";
     
     }   
 }
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

Answer by Numli · Sep 09, 2015 at 09:58 AM

You need to include the interface reference to your class and also onPointerEnter requires a parameter of PointerEventData.

See http://docs.unity3d.com/ScriptReference/UI.Selectable.OnPointerEnter.html for a simple example.

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 Frenzy-Alex · Sep 09, 2015 at 10:23 AM 0
Share

I tried, but if I for example, create five ComboBoxText, and touch one of five, event OnPointerEnter() called on all five ComboBoxText... But code is true, except PointerEnter EventTrigger.. for example if I change it on PointerDown or PointerExit, it works well. But PointerEnter has call only when I click on object..

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do you trigger a specific collider using OnTriggerEnter? 2 Answers

How to rotate an object like item inspection when entering a trigger? 1 Answer

Create custom Triggerevent 0 Answers

[Unity5 C#] OnTriggerEnter not working 1 Answer

How do I hide methods from the animation event inspector window? 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