unity官网教程——Roll-a-ball tutorial——2摄像机跟随

参考网址:https://unity3d.com/cn/learn/tutorials/projects/roll-ball-tutorial/moving-camera?playlist=17141

https://unity3d.com/cn/learn/tutorials/projects/roll-ball-tutorial/moving-camera?playlist=17141

实现结果: Camera跟随player小球移动

代码:

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 
 5 public class CameraController : MonoBehaviour
 6 {
 7     public GameObject mPlayerball = null;
 8     private Vector3 mCameraOffsetVec = Vector3.zero;
 9 
10     private void Start()
11     {
12         if (mPlayerball != null)
13         {
14             mCameraOffsetVec = transform.position - mPlayerball.transform.position;
15         }
16     }
17 
18     private void LateUpdate()
19     {
20         if (mPlayerball != null)
21         {
22             transform.position = mPlayerball.transform.position + mCameraOffsetVec;
23         }
24     }
25 }

 

总结:针对LateUpdate:

  • However, for follow cameras, procedural animation,and gathering last known states it's best to use LateUpdate. LateUpdate runs every frame, just like update.But it is guaranteed to run after all items have been processed in update.

     

    LateUpdate在所有脚本的Update之后执行。

    针对Update之后进行最后的数据处理。例如:摄像机跟随、代码动画、获取最终状态。

     

 

转载于:https://www.cnblogs.com/sun-shadow/p/7882033.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值