- Home /
How should I check is pointer over an ui image?
I tried with Pointer Enter but that didn't work very well. http://postimg.org/image/z1dw3llyl/6c2abf4b/ It worked only when moving cursor from outside. Idea is that player should keep right mouse button pressed when selecting a segment.
The EventTrigger PointerEnter should be used with PointerExit to switch a bool in script to true when entering and false when exiting. It is the correct way to go about this so what issues did you get?
Answer by Mmmpies · Feb 28, 2015 at 04:36 PM
So set a bool as I said.
private bool hovering = false;
void Update()
{
if(hovering)
Debug.Log(gameObject.name);
}
public void OnPointyEnter()
{
hovering = true;
}
public void OnPointyExit()
{
hovering = false;
}
Of course in the Update you'll want to handle the Input from the right button but put this script on each image and change the name of each image so it reports back when over that image.
You also need to Add the PointerExit and PointerEnter for each button.
Not tested the code though so may contain typos!
Answer by tayyab43 · Feb 28, 2015 at 04:19 PM
OnHover should be used
There is no such thing. http://s12.postimg.org/v6kgr8zhp/N_ytt_kuva_2015_02_28_kello_18_31_25.png
oh your using Unitys new UI system, try adding this code:
http://docs.unity3d.com/ScriptReference/GUIStyle-onHover.html
OnGUI is old UI system @tayyab43, the new system works with Events and I can highly recommend it, very very powerful and so much better than the old GUI. Got some issues (I don't care too much for the anchor system myself) but the Event System is a work of genius.
true, i am using it but its just getting used to it is a bit annoying, im so used to the old system that i prefer using it for things like trying to to get buttons on certain places no matter what the screen size is and things like that.
Your answer
![](https://koobas.hobune.stream/wayback/20220613184612im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[Unity 4.6] Button Tracking UI System? 0 Answers
(c#) Photon networking, get players in room? 1 Answer
4.6 UI Text rect does not expand automatically 2 Answers
Unity 4.6 button movement problem 1 Answer
[4.6 - UI] Keep aspect ratio 2 Answers