using UnityEngine; public class UIFollowTarget_Ino : MonoBehaviour { /// /// 3D target that this object will be positioned above. /// public Transform target; public bool isTarget; /// /// UI 위치 오프셋, z는 0 /// public Vector3 offSet; /// /// UI camera to use. /// public Camera uiCamera; bool isUICam; Transform mTrans; int mIsVisible = -1; /// /// Whether the target is currently visible or not. /// public bool isVisible { get { return mIsVisible == 1; } } public bool runUpdate { get; set; } /// /// Cache the transform; /// void Awake() { mTrans = transform; } /// /// Update the position of the HUD object every frame such that is position correctly over top of its real world object. /// void Update() { if (runUpdate) { if (!isUICam) { uiCamera = NewGameUI.Ins.UICamera; isUICam = uiCamera; } if (isTarget && isUICam) { Vector3 pos = Camera.main.WorldToViewportPoint(target.position); // Determine the visibility and the target alpha //int isVisible = (gameCamera.orthographic || pos.z > 0f) && (pos.x > 0f && pos.x < 1f && pos.y > 0f && pos.y < 1f) ? 1 : 0; //bool vis = (isVisible == 1); // If visible, update the position //if (vis) { pos = mTrans.parent.InverseTransformPoint(uiCamera.ViewportToWorldPoint(pos)); pos.z = 0f; mTrans.localPosition = pos + offSet; } } else gameObject.SetActive(false); } } }