Question by
J0hnC0nn0r · Oct 16, 2020 at 12:23 PM ·
gameobjectevent triggeringlistenertooltipevent-listener
Adding a listener to bar's on a bargraph issue...
I'm trying too add a listener too this gameobject but I'm not really familiar with listeners and I got this code from another post so I'm probably not implementing this correctly. could someone help me out here? I've been trying to figure out how to get these objects to be detectable when the mouse moves across it so I can run a tooltip function that display's the bar graphs value.
private GameObject CreateBar(Vector2 graphPos, float barWidth)
{
GameObject gameObject = new GameObject("bar", typeof(Image));
gameObject.transform.SetParent(graphContainer, false);
gameObject.GetComponent<Image>().color = barColor;
gameObject.AddComponent<Button>();
gameObject.AddComponent<Renderer>();
gameObject.AddComponent<EventTrigger>();
EventTrigger evtTrigger = gameObject.GetComponent<EventTrigger>();
// On Pointer Enter
EventTrigger.TriggerEvent trigger = new EventTrigger.TriggerEvent();
trigger.AddListener((idObject) => { gameObject.GetComponent<Window_Graph>().ShowTooltip(); });
EventTrigger.Entry entry = new EventTrigger.Entry()
{
callback = trigger,
eventID = EventTriggerType.PointerEnter
};
evtTrigger.triggers.Add(entry);
// On Pointer Exit
EventTrigger.TriggerEvent trigger2 = new EventTrigger.TriggerEvent();
trigger2.AddListener((eventData) => { gameObject.GetComponent<Window_Graph>().ShowTooltip(); });
EventTrigger.Entry entry2 = new EventTrigger.Entry
{
callback = trigger2,
eventID = EventTriggerType.PointerExit
};
evtTrigger.triggers.Add(entry2);
Comment
Your answer
Follow this Question
Related Questions
How would I go about adding a tooltip to a Unity UI Image? 0 Answers
CardBoard Project. Instatiate prefab don't interact with Player 0 Answers
gameObjects working in one scene, but none of the others? 1 Answer
How to trigger an event when camera collides with a gameobject or is near that gameobject ? 2 Answers