不多BB,直接上代码
public Transform follow;//跟随目标
public float xMove = 0; //鼠标横向偏移量
public float yMove = 0; //鼠标垂直偏移量
public float distance = 2; //摄像机离目标的距离
public float height = 1.5f;//摄像机高度
private void Update()
{
xMove += Input.GetAxis("Mouse X");
yMove -= Input.GetAxis("Mouse Y");
transform.rotation = Quaternion.Euler(yMove, xMove, 0);
var negDistance = new Vector3(0.0f, 0.0f, -distance);
transform.position = transform.rotation * negDistance;
}
private void LateUpdate()//写在这防抖动
{
transform.position += (follow.position + Vector3.up * height);
}