相机跟随角色移动镜头缩放方法
这种方法最简单可以实现相机跟随角色平移
1:计算相机和目标物体的距离
offset = this.transform.position - target.transform.position;
2:Update方法中实时变化相机位置
this.transform.position = target.transform.position + offset;
3:镜头缩放
//镜头缩放 public void CamRotation() { if (Input.GetAxis("Mouse ScrollWheel") != 0) { //鼠标滚动滑轮 值就会变化 if (Input.GetAxis("Mouse ScrollWheel") < 0) { //范围值限定 if (Camera.main.fieldOfView <= 100)//摄像机采用Perspective透视 Camera.main.fieldOfView += 2; if (Camera.main.orthographicSize <= 20)//摄像机采用Orthograpic正交 Camera.main.orthographicSize += 0.5F; } //Zoom in if (Input.GetAxis("Mouse ScrollWheel") > 0) { //范围值限定 if (Camera.main.fieldOfView > 2)//摄像机采用Perspective透视 Camera.main.fieldOfView -= 2; if (Camera.main.orthographicSize >= 1)//摄像机采用Orthograpic正交 Camera.main.orthographicSize -= 0.5F; } } }