- 固定跟随,无效果(意义不大)
1 public class FollowPlayer : MonoBehaviour 2 { 3 public Transform Player; 4 private Vector3 Offset; 5 6 void Start() 7 { 8 //设置差值 9 Offset= Player.position - transform.position; 10 } 11 12 void Update() 13 { 14 transform.position = Player.position - Offset; 15 } 16 }
- 差值跟随,有缓冲(推荐)
public class FollowPlayer : MonoBehaviour { public Transform Player; private Vector3 Offset; private int Speed = 2; void Start() { Offset = Player.position - transform.position; } void Update() { //调整相机与玩家之间的距离 transform.position = Vector3.Lerp(transform.position, Player.position - Offset, Speed * Time.deltaTime); } }
原文地址:https://www.cnblogs.com/M-fengye/p/9528590.html
时间: 2024-11-17 12:51:30