效果图:
设置如下:
摄像机设置: using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFllow : MonoBehaviour { public GameObject tank1; public GameObject tank2; Vector3 offset; // Use this for initialization void Start () { offset=transform.position- (tank1.transform.position +tank2.transform.position)/2;//相机默认偏移量(相机看向坦克中心的向量) } // Update is called once per frame void Update () { if (tank1==null||tank2==null) { return; } transform.position = (tank1.transform.position + tank2.transform.position) / 2 + offset;//相机时刻跟踪中心位置 float dis = Vector3.Distance(tank1.transform.position,tank2.transform.position);//两个坦克距离 GetComponent<Camera>().orthographicSize = dis * 0.4f;//坦克距离有正交摄像机的Size成比例 } }