12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class LabelObjectScript : MonoBehaviour
- {
- Camera camera;
- public GameObject target;
- public RectTransform canvasRect;
- public GameObject text;
-
- void Start()
- {
-
- }
-
- void Update()
- {
-
- float offsetPosY = target.transform.position.y + 1.5f;
-
- Vector3 offsetPos = new Vector3(target.transform.position.x, offsetPosY, target.transform.position.z);
-
- Vector2 canvasPos;
- Vector2 screenPoint = Camera.main.WorldToScreenPoint(offsetPos);
-
- RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, null, out canvasPos);
-
-
- text.transform.localPosition = canvasPos;
- }
- }
|