Alright! I have a game in which the character moves when I tap/click. Like Flappy Bird!
But I want to add other actions that need to be buttons.
My question is… Can I add UI buttons that will work without triggering the tap/click movements or Do I need to make the tap/click movement a UI button of its own?
You can loop through your UI and then only perform the tap if no UI under the cursor.
or
You could flip a switch telling your application not to perform a tap when a UI button is triggered.
I do this with a pointer, but I believe it should be similar with tap controls. Set your buttons to a “UI” physics layer. Within an input class or something you could track the “cursor position” and create PointerEventData then do a RaycastAll(PointerEventData, RaycastResylts). Check if the results has hit anything and if it has check if that is the UI layer. If it has, don’t allow the jump action to happen. Here’s code if that’s confusing:
public static bool IsHoveringUIElement()
{
PointerEventData pointerData = new PointerEventData(EventSystem.current) { pointerId = -1, };
pointerData.position = GetCursorPos();
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, results);
if (results.Count > 0)
{
return results[0].gameObject.layer == 5; // 5 is Unity's UI layer
}
return false;
}