using System.Collections; using System.Collections.Generic; using UnityEngine; // 专门用来渲染player character的相机,用来做特效 [RequireComponent(typeof(Camera))] public class UnitCamera : MonoBehaviour { PCController pc { get { return UnitManager.Instance.pc; } } Camera m_Camera; private void OnEnable() { m_Camera = GetComponent(); } private void OnPreRender() { if (pc == null) return; if (m_Camera == null) return; Vector3 pos = transform.position; transform.position = new Vector3(pc.center.x, pc.center.y, pos.z); float dz = Mathf.Abs(pos.z - pc.center.z); float fov = 2 * Mathf.Atan2(pc.unitDetail.snapshotBound / 2, dz) * Mathf.Rad2Deg; m_Camera.fieldOfView = fov; } }