using System.Collections; using System.Collections.Generic; using UnityEngine; public class ZoneUI : MonoBehaviour { public Camera _camera; public Transform target; public Vector3 offset=Vector3.zero; private Vector3 startScale; public bool isScreen = true; public bool isCameraDistance = false; private float distanceScale; Vector3 pos; private void Start() { if (_camera == null) { _camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent(); } startScale = transform.localScale; } public void Update() { if (isScreen) { if (isCameraDistance) { distanceScale = Vector3.Distance(_camera.transform.position, target.transform.position) * Level3Manager.Instance.KuangDistanceValue; pos = _camera.WorldToScreenPoint(target.position); this.transform.localScale = distanceScale * startScale; } else { pos = _camera.WorldToScreenPoint(target.position); } } else { pos = target.position; transform.localScale = startScale; transform.LookAt(_camera.transform); } transform.position = pos + offset; //transform.LookAt(_camera.transform); } }