GibTreaty

Basic Tooltip Example

Oct 19th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3.  
  4. public class Tooltip : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
  5.     PointerEventData data;
  6.  
  7.     public RectTransform tooltip;
  8.  
  9.     void Start() {
  10.         tooltip.gameObject.SetActive(false);
  11.     }
  12.  
  13.     void Update() {
  14.         if(data != null)
  15.             tooltip.position = data.position + new Vector2(0, -tooltip.sizeDelta.y);
  16.     }
  17.  
  18.     public void OnPointerEnter(PointerEventData eventData) {
  19.         data = eventData;
  20.         tooltip.gameObject.SetActive(true);
  21.     }
  22.  
  23.     public void OnPointerExit(PointerEventData eventData) {
  24.         tooltip.gameObject.SetActive(false);
  25.         data = null;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment