unity相机跟随Player常用方式

  1. 固定跟随,无效果(意义不大)
     public class FollowPlayer : MonoBehaviour
    {
    public Transform Player;
    private Vector3 Offset; void Start()
    {
    //设置差值
    Offset= Player.position - transform.position;
    } void Update()
    {
    transform.position = Player.position - Offset;
    }
    }
  2. 差值跟随,有缓冲(推荐)
    public class FollowPlayer : MonoBehaviour {
    
        public Transform Player;
    
        private Vector3 Offset;
    private int Speed = ; void Start()
    {
    Offset = Player.position - transform.position;
    } void Update()
    {
    //调整相机与玩家之间的距离
    transform.position = Vector3.Lerp(transform.position, Player.position - Offset, Speed * Time.deltaTime);
    }
    }
  3. 有其他需要,参考Unity知识总结系列(二):相机跟随人物的几种方式_崔小妹儿Jessica的博客-CSDN博客
上一篇:2018-12-09 疑似bug_中文代码示例之Programming in Scala笔记第九十章


下一篇:Windows下安装单机Kafka