using UnityEngine;
using System.Collections;
public class FollowTarget : MonoBehaviour {
public Vector3 offset; // 把摄像机放在人物的子节点,得到的位置信息 得到后 再吧摄像机拖回原来的位置
private Transform player;
// Use this for initialization
void Start () {
player = GameObject.FindGameObjectWithTag("Player").transform;
}
// Update is called once per frame
void Update () {
transform.position = player.position + offset;
}
}
public Transform target;
public float distance;
public float targetHeight;
private float x = 0.0f;
private float y = 0.0f;
void Start()
{
var angles = transform.eulerAngles;
x = angles.x;
y = angles.y;
}
void LateUpdate()
{
if (!target)
return;
y = target.eulerAngles.y;
// ROTATE CAMERA:
Quaternion rotation = Quaternion.Euler(x, y, 0);
Quaternion rrr= Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime*3f);
transform.rotation = rrr;
// POSITION CAMERA:
Vector3 position = target.position - (rotation * Vector3.forward * distance + new Vector3(0, -targetHeight, 0));
Vector3 pp = Vector3.Lerp(transform.position, position, Time.deltaTime*3f);
transform.position = pp;
}