Hello guys, I’m having a problem with event trigger and I don’t know how to fix.
Basically what I’m doing is this:
I have an interactive map in which you can select countries. Once you click a country the map scales, giving the impression it’s zooming, and it shows some cities. These cities are gameobjects and each one of them has a EventTrigger component attached with PointerEnter and PointerExit, which I’m using to make an highlight effect.
I have 30 cities: 25 of them work and 5 don’t.
I noticed that if I move the icon’s position up or down, at a certain point, the trigger starts to work as if there was some kind of area that doesn’t allow the trigger to do what’s supposed to.
First off, DON’T USE EVENTTRIGGERS they are bulky and overweight and shouldn’t be used for just click events. Better to write a simple script and use the event interfaces like
As to the positional issue, this is likely due to the graphic area of the GO your EventTrigger is attached to, as the UI system uses (by default) a graphical raycast to test the image component with a users touch, so by moving the image you are altering where the raycast will be detected.
Hope that helps
First of all thanks a lot for the answer! I replaced the EventTrigger with the interfaces as you said
Unfortunally the same problem persists and while I got that it has to do with the raycast, I didn’t quiet get how to fix it
Oh and by the way I’m using Screen Overlay as render mode
From the images that is truly baffling, as one of the “not working” buttons is in between the others (from a height perspective.
Is there an issue with altering their height for the non-working one’s to a position that works?
or is it the height of the image it’self that is causing an issues (I expect not as they look the same height).
If that doesn’t answer it, a sample project will be needed of just that screen (possibly not even with the correct art) to see further.
Tomorrow I can try to send you a project, thanks a lot for your time btw
All the pictures have the same size. If I increase the height of a bugged one, then the pointer works just from a certain point. For example if I make the first bugged picture higher (which works for like the 5% of it), then it works for 10%, 15% and more (based on how bigger it is)
Found the problem, didn’t take too long. Although best to take your shoes off so you don’t kick yourself too hard .
Basically, the reason the towers that aren’t working are being overlayed by other UI objects, namely the world panels. It’s nothing to do with the towers themselves, as you can see here:
To solve this (without having to resize all the worlds RectTransforms), simply add a CanvasGroup to each World. Then when you are zoomed in to one world, turn off “Blocks Raycasts” (the default behaviour of an overlapping panel) on the other worlds.
So “Blocks” Raycasts ON for the zoomed in world, OFF for the others.
So I’d suggest, adding it to each world with “Blocks Raycasts” off, then turn it on when you Zoom in.
P.S.
I’d recommend using Prefabs for towers and worlds to make you life and management a lot easier