最近在写关于相机跟随的逻辑,其实最早接触相机跟随是在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 }
简单相机移动

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2021-07-20
  • 2021-10-04
  • 2022-01-25
猜你喜欢
  • 2021-10-12
  • 2021-10-22
  • 2022-12-23
  • 2021-06-08
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案