- Home /
Multiple colliders using IPointerEnter/ExitHandler
I have an area with the script below, where when I mouse over it, 3 buttons should show up, which are in buttonContainer. I now want to be able to hover and click these buttons. And when I move the mouse out of the area, the 3 buttons should hide again.
The problem is that when I then hover over the buttons, inside the buttonContainer, OnPointerExit of the container is triggered, so it hides the buttons, again triggering the buttonContainer OnPointerEnter, and causing it to flicker on off.
The colliders are all in separate objects. I'm using IPointerEnterHandler and IPointerExitHandler like this:
public class WaypointHover : MonoBehaviour,IPointerEnterHandler, IPointerExitHandler {
public GameObject buttonContainer;
public void OnPointerEnter(PointerEventData eventData) {
buttonContainer.SetActive(true);
}
public void OnPointerExit(PointerEventData eventData) {
buttonContainer.SetActive(false);
}
}
How can I set this up so I have multiple colliders, that react no matter what's behind or in front of them?
Should I have a raycast on the mouse for each frame, forever, to raycast and use layers? Would the be performance intensive?
Isn't there some simpler way of using IPointerEnterHandler, mouseDown or similar and just grab multiple colliders at once?
Thanks!
what's the setup in terms of collision? everything using colliders? 2D or 3D? what's the depth order?
Answer by nicmarxp · Oct 26, 2018 at 08:59 PM
Solved it by setting the buttons in a separate layer, and then doing raycasting only this layer while hovering on the area where they are showing. It takes a little fiddling with the colliders, to make sure the inner colliders don't stick up above the outer. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612181024im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object movement, collider and Physics. 0 Answers
Raycast Without Colliders 6 Answers
[2D] Raycast to mouse cursor = offset on Y axis 0 Answers
Click&Drag Misterious Disappearing! 1 Answer