| 1234567891011121314151617181920212223242526 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class TargetDistanceLabel : MonoBehaviour
- {
- public RectTransform canvasRTF;
- public Camera mainCamera;
- public Transform followTarget;
- TargetBody targetBody;
- Vector3 centerPoint = new Vector3(0.5f, 0.5f, 0);
- void Start()
- {
- targetBody = GameObject.Find("GameArea/010").GetComponentInChildren<TargetBody>();
- }
- void LateUpdate()
- {
- Vector3 v3 = mainCamera.WorldToViewportPoint(followTarget.position) - centerPoint;
- v3.x *= canvasRTF.rect.width;
- v3.y *= canvasRTF.rect.height;
- v3.z = 0;
- this.transform.localPosition = v3;
- this.GetComponent<Text>().text = ((int)Mathf.Round(targetBody.GetDistance())) + "M";
- }
- }
|