-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonMouseSelectScript.cs
More file actions
42 lines (31 loc) · 1.17 KB
/
ButtonMouseSelectScript.cs
File metadata and controls
42 lines (31 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
// Unless denoted by a commented out link, TK wrote literally everything here
// Helped me do this:
// https://gamedev.stackexchange.com/questions/116801/how-can-i-detect-that-the-mouse-is-over-a-button-so-that-i-can-display-some-ui-t
// Note to self, another way to do this:
// https://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html
public class ButtonMouseSelectScript : MonoBehaviour, IPointerEnterHandler
{
public void OnPointerEnter(PointerEventData pointerEventData)
{
// Select a button when hovering over it with mouse
Button btn = GetComponent<Button>();
btn.Select();
}
}
/* This does not work on UI eleements:
void OnMouseOver()
{
//If your mouse hovers over the GameObject with the script attached, output this message
Debug.Log("Mouse is over GameObject.");
}
void OnMouseExit()
{
//The mouse is no longer hovering over the GameObject so output this message each frame
Debug.Log("Mouse is no longer on GameObject.");
}
*/