//物体必须带collider
using UnityEngine;
using System.Collections;using UnityEngine.UI;
public class Cube : MonoBehaviour
{
public Text text;
public Canvas canvas;
void OnMouseEnter()
{
text.gameObject.SetActive(true);
Vector2 _pos = Vector2.one;
RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
Input.mousePosition, canvas.worldCamera, out _pos);
text.gameObject.transform.localPosition = _pos;
}
void OnMouseExit()
{
text.gameObject.SetActive(false);
}
}