Have a component ignore all other overlapping raycasts for PointEnter and Exit events?
I have a script that detects if the pointer has entered the opaque part of an image, trues a bool, then prints a debug if it leaves the same opaque part of an image and the bool is true:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using AC;
public class InventoryHoverOff : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
private bool hoverAway = false;
private Image SheetImage;
public float AlphaThreshold = 0.1f;
void Start()
{
this.GetComponent<Image>().alphaHitTestMinimumThreshold = AlphaThreshold;
}
void Awake()
{
SheetImage = GetComponent<Image>();
}
// Update is called once per frame
void Update()
{
InvItem selectedItem = KickStarter.runtimeInventory.SelectedItem;
if (selectedItem == null)
{
hoverAway = false;
}
}
public void OnPointerEnter(PointerEventData eventData)
{
//Debug.Log("Entered the sheet");
InvItem selectedItem = KickStarter.runtimeInventory.SelectedItem;
if (selectedItem != null)
{
hoverAway = true;
}
}
public void OnPointerExit(PointerEventData eventData)
{
if (hoverAway == true)
{
Debug.Log("left the page");
}
}
}
The trouble is, I have a few buttons that need to detect clicks that area overlapping this image, and they block the raycasts from the image pointer events: https://gfycat.com/FearlessUnsightlyFugu - towards the end you can see the buttons cause the script to think the point has left the image when it overlaps a button. Is there any way of having this single image component only recognise raycasts from itself and totally ignore any buttons situated above it?
Your answer
![](https://koobas.hobune.stream/wayback/20220612165325im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mobile game, Touchscript pass through UI 1 Answer
Panel content size fitter not working 2 Answers
Problem rendering an image in a canvas 0 Answers
Black UI when building to android 1 Answer