Unity3d相机跟随角色移动

using UnityEngine;
using System.Collections;

public class follwCam : MonoBehaviour {
	public Transform targetTr;
	public float dist = 10f;
	public float height = 3.0f;
	public float dampTrace = 20.0f;

	public Transform tr;
	// Use this for initialization
	void Start () {
		tr = GetComponent ();
	}
	
	// Update is called once per frame
	void LateUpdate () {
		tr.position = Vector3.Lerp (tr.position, targetTr.position - (targetTr.forward * dist) + (Vector3.up * height), Time.deltaTime * dampTrace);
		tr.LookAt (targetTr.position);
	}
}
targetTr : 要追踪的游戏对象Transform为变量
dist:与摄像机之间的距离

height : 设置摄像机的高度
dampTrace : 实现平滑追踪的变量


你可能感兴趣的:(unity3d,C#)