- Home /
The question is answered, right answer was accepted
Change Mouse Icon on UI Hover
I want to change my mouse icon to another icon when I hover over an UI Element. The text-color is already changing, but Im not able to get the mouse icon to change. The Base Mouse Icon is the pencile, when hovering over the menu, it should change to the hand with the index finger.
My MouseChange code is as follows:
public Texture2D defaultTextureMouse;
public Texture2D exitTextureMouse;
public CursorMode curModeMouse = CursorMode.Auto;
public Vector2 hotSpotMouse = Vector2.zero;
// Use this for initialization
void StartMouse () {
Cursor.SetCursor(defaultTextureMouse, hotSpotMouse, curModeMouse);
}
public void OnMouseEnter()
{
if (gameObject.tag == "exit")
{
Cursor.SetCursor(exitTextureMouse, hotSpotMouse, curModeMouse);
}
}
public void OnMouseExit()
{
Cursor.SetCursor(defaultTextureMouse, hotSpotMouse, curModeMouse);
}
I know that I have to make something with the EventTrigger. However, I dont know how to connect the script to the detection of hovering the mouse over any of the UI Text Elements. It isnt working with any Box Collider, because its a UI, right? I also dont know where to place the script to.
Picture shows that I have HyperTextEvents for the color to change from black to blue and back when hovering with the mouse.
I hope you guys can help me and if you need any more informations, let me know. I hope i can answer them, because I just got that project without any documentation and im also new to Unity :/
Answer by Rajeesh_AR · Jul 12, 2018 at 05:17 AM
HI, For the UI, you have to include the "EventTrigger". Attach the MouseChange.cs script to a GameObject. Whatever be the object (either a new empty GameObject or even Camere). Pls check your code. The code which you copied here doesn't have the Class name.
Then select the UI component which you need to perform the MouseHover action. In that> Add Component > Event Trigger > Add New Event Type > PointerEnter > Click the '+' and drag and drop the GameObject in which you added your MouseChange.cs script. Select "OnMouseEnter".
Now, on the same UI element, Add Component > Event Trigger > Add New Event Type > PointerExit > Click the '+' and drag and drop the GameObject in which you added your MouseChange.cs script. Select "OnMouseExit".
Thank you so much. I didnt copied the the first 3 lines because i thought those are standard, doing it in future questions, anyway, thank you so much. It works now an now I even understand how this Event Trigger works. You are the best
Follow this Question
Related Questions
PauseMenu - Camera moves in pausemenu 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
make an object glow when mouse over 3 Answers