方式一:将摄像机直接拖到游戏对象的下面;
方式二:脚本实现
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class kow : MonoBehaviour 6{ 7 public Transform targetTr; 8 public float dist = 10.0F; 9 public float height = 3.0F; 10 public float dampTrace = 20.0F; 11 12 private Transform tr; 13 14 // Start is called before the first frame update 15 void Start() 16 { 17 tr = GetComponent<Transform>(); 18 } 19 20 // Update is called once per frame 21 void LateUpdate() 22 { 23 tr.position = Vector3.Lerp(tr.position, targetTr.position - (targetTr.forward * dist) + (Vector3.up * height), Time.deltaTime * dampTrace); 24 tr.LookAt(targetTr.position); 25 } 26}
这里主要的是Vector3.Lerp()和函数,三个参数,第一个:起始位置;第二个:结束位置;第三个:浮点格式。