using UnityEngine;
using System.Collections;
/// <summary>
/// 摄像机的跟随
/// </summary>
public class Follow : MonoBehaviour
{
//目标
public Transform target;
//向后的距离
public float backDistance = 2;
//高度
public float topDistance = 2;
//俯角
public float lookDgree = 30f;
void Start()
{
}
//总是晚于Update,适合做跟随效果
void LateUpdate()
{
//计算目标的自身坐标系正后方位置
Vector3 end = -target.forward * backDistance + target.up * topDistance;
transform.position = target.position + end;
//计算旋转,保持跟目标一样
transform.rotation = target.rotation * Quaternion.Euler(lookDgree, 0, 0);
}
}