/// <summary> /// 在透视投影时,改变相机的fov或物体的位置,让物体保持在屏幕上看起来的大小一样的缩放值 /// </summary> /// <returns></returns> public static float KeepSizeLookSameScale(Vector3 pos, Camera cam) { float distance = Vector3.Distance(cam.transform.position, pos); float size = distance * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad); float max = 100f * Mathf.Tan(122 * 0.5f * Mathf.Deg2Rad); float scale = size / max; //scale = Mathf.Clamp(scale, 0.01f, 0.1f);//限定一个最大值和最小值 return scale; }
标签:scale,物体,float,Mathf,pos,unity,cam,不变 From: https://www.cnblogs.com/Jason-c/p/17119010.html