最近在写关于相机跟随的逻辑,其实最早接触相机跟随是在Unity官网的一个叫Roll-a-ball tutorial上,其中简单的涉及了关于相机如何跟随物体的移动而移动,如下代码:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class CameraController : MonoBehaviour {
 5 
 6     public GameObject player;
 7 
 8     private Vector3 offset;
 9 
10     void Start ()
11     {
12         offset = transform.position - player.transform.position;
13     }
14     
15     void LateUpdate ()
16     {
17         transform.position = player.transform.position + offset;
18     }
19 }
简单相机移动

相关文章: