using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour {
public Transform target;
// The distance in the x-z plane to the target
public float distance = 10.0f;
// the height we want the camera to be above the target
public float height = 5.0f;
void LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= Vector3.forward * distance;
transform.position = new Vector3(transform.position.x,transform.position.y + height,
transform.position.z);
// Always look at the target
// transform.LookAt (target);
}
}
转载于:https://www.cnblogs.com/bzyzhang/p/5399622.html