原视频链接
Messages of MonoBehaviour
物理阶段
MonoBehaviour.FixedUpdate()
每隔固定时间(时间可以修改)执行一次。适合对物体做物理操作,不会受到渲染影响。
输入事件
MonoBehaviour.OnMouseDown()
OnMouseDown is called when the user has pressed the mouse button while over the Collider. 所以如果没有激活或者没有 collider 组件的话点击无效。
游戏逻辑阶段
MonoBehaviour.Update()
渲染帧执行,执行间隔不固定。适合处理游戏逻辑。MonoBehaviour.LateUpdate()
在Update
函数被调用后执行,适用于跟随逻辑。 例如对于相机跟随,物体移动写在Update
,相机跟随写在LateUpdate
。
场景渲染
MonoBehaviour.OnBecameVisible()
OnBecameVisible is called when the renderer became visible by any camera.(就那一帧)MonoBehaviour.OnBecameInvisible()
OnBecameInvisible is called when the renderer is no longer visible by any camera.(就那一帧)
结束阶段
MonoBehaviour.OnDisable()
This function is called when the behaviour becomes disabled.MonoBehaviour.OnDestroy()
Destroying the attached Behaviour will result in the game or Scene receiving OnDestroy.MonoBehaviour.OnApplicationQuit()
Sent to all game objects before the application quits. In the editor this is called when the user stops playmode.
调试
控制台调试
Debug. Log ( ) ;
MonoBehaviour. print ( ) ;
写公开变量,直接查看
public float time;
void Update ( )
{
time = Time. time;
}