all repos — RPG @ e75221ea3d14613e26def0c193decf24d4458235

Fully functional 3D turn based role playing game coded in C# and base Unity.

Assets/Scripts/Utility/MouseOverInfo.cs (view raw)

 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.EventSystems;
 5using UnityEngine.UI;
 6
 7[RequireComponent(typeof(ActionButton))]
 8public class MouseOverInfo : MonoBehaviour
 9{
10    public Text status_text;
11    
12    private PointerEventData pe = new PointerEventData(EventSystem.current);
13    private List<RaycastResult> hits;
14    private ActionButton btn = null;
15    private ActionButton oldBtn = null;
16
17    private void Start()
18    {
19        oldBtn = GetComponent<ActionButton>();
20    }
21
22    void Update()
23    {
24        pe.position = Input.mousePosition;
25        hits = new List<RaycastResult>();
26        EventSystem.current.RaycastAll(pe, hits); //Raycast
27
28        foreach (RaycastResult h in hits)
29        {
30            btn = h.gameObject.GetComponent<ActionButton>();
31            if (btn)
32            {
33                if (!btn.Equals(oldBtn))
34                {
35                    oldBtn = btn;
36                    UI.changeText(status_text, btn.getDescription());
37                }
38            }
39        }
40    }
41}