using UnityEngine;
public class 2DLabelFollow3DObj: MonoBehaviour{
public Transform targetObj;
public GameObject labelObj;
private void Update()
{
UpdateLabel(targetObj);
}
private void UpdateLabel(Transform target)
{
RectTransform labelRt=label.Getcomponent<RectTransform()>;
Vector3 screenPos=Camera.main.WorldToScreenPoint(target.Position);
RectTransform rect=GameObject.Find("Canvas").GetComponent<RectTransform>;
Vector2 outVec;
if(RectTransformUtility.ScreenPointToLocalPointInRectangle(rect,screenPos,null,out outVec))
outVec+=new Vector2(0,-GameObject.Find("Canvas").transform.Find("Panel").localPosition.y);
}
labelRt.anchoredPosition=outVec;
}