第二, 给摄像机拖脚本。就像噩梦射手里面的那样,摄像机俯视整个场景,然后就会跟随主角移动,但是不会旋转。
代码如下:
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour {
public Transform target ;
Vector3 offset ;
public float smooth = 5.0f;
// Use this for initialization
void Start () {
offset = transform.position - gameObject.transform.position;
}
// Update is called once per frame
void FixedUpdate () {
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp (transform.position,targetCamPos,smooth *Time.deltaTime);
}
}