- Home /
UI: Tooltip for multiple images behind bigger button?
I have a crafting window with a couple of images for a crafting recipe. When I hover each, I see a tooltip of what it is, but on top of all images I have a bigger button that I can click to craft that item. I could make each image clickable, but I'd like the button/border of all icons to be highlighted when hovered.
I'm using IPointerEnterHandler to receive mouseover events to show the tooltip. But when there is a button on top of it, the OnPointerEnterEvent doesn't fire.
Is there a way to combine these, so the raycast still goes through to the IPointerEnterHandler, and at the same time the button works like a normal button?
Or do I have to code my own solution with raycasts, like "if mouse is over any icon, show border", "if anything is clicked, craft item".
Thank you in advance!
Answer by kaplica · Feb 24, 2019 at 10:33 PM
Can you not use triggers? https://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html
Update
I know what you mean now, sorry. I am using this script for my sidebar navigational menu in my app, it helps me to pin point what user taps on.
if (Input.touchCount > 0)
{
var touch = Input.GetTouch(0);
PointerEventData pointerData = new PointerEventData(EventSystem.current);
pointerData.position = touch.position;
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, results);
if (results.Count > 0)
{
if (results[0].gameObject.layer != LayerMask.NameToLayer("UI - Sidebar"))
{
Debug.Log("Root Element" + results[results.Count-1].gameObject.name + " Child" + results[0].gameObject.name);
results.Clear();
}
}
}
Thanks, I will check it out. But does this allow events to pass through layers of UI elements, so I can have a "OnPointerEnter" on the image and at the same time "On$$anonymous$$ouseDown" on the button that is above?
Please see my updated answer. This has to be ran every frame by the way, so in Update, or FixedUpdate if you want it to run at the end of each frame.
Thanks a lot, will try and confirm the answer when I find that it works :)
Your answer
Follow this Question
Related Questions
How to use two Canvases in Unity 4.7 ? 0 Answers
Buttons and Event Triggers kill FPS 0 Answers
How i set image from Raycast hit target object? 2 Answers
Display issues with GUI only showing details for last object in list. 2 Answers
Different between IPointerClickHandler.OnPointerClick and MonoBehaviour.OnMouseDown 1 Answer