返回介绍

MonoBehaviour

发布于 2019-12-18 15:38:02 字数 18158 浏览 803 评论 0 收藏 0

Namespace: UnityEngine

Inherits from: Behaviour

Description 描述

MonoBehaviour is the base class every script derives from.

MonoBehaviour 是每个脚本派生的类的基类。

Using Javascript every script automatically derives from MonoBehaviour. When using C# or Boo you have to explicitly derive from MonoBehaviour.

每个Javascript脚本自动继承MonoBehaviour,使用C#或Boo时,需要显式继承MonoBehaviour.

Note: The checkbox for disabling a MonoBehavior (on the editor) will only prevent Start(), Awake(), Update(), FixedUpdate(), and OnGUI() from executing. If none of these functions are present, the checkbox is not displayed.

注意:MonoBehavior对象(编辑器中)的复选框,只有在其有Start(),Awake(),Update(), FixedUpdate()和 OnGUI()函数时显示,没有这些函数时则隐藏。

See Also: The chapter on scripting in the manual.

Variables 变量

useGUILayoutDisabling this lets you skip the GUI layout phase.
禁用此项,将会跳过GUILayout布局。

Functions 函数

CancelInvokeCancels all Invoke calls on this MonoBehaviour.
在当前MonoBehaviour,取消所有Invoke调用
InvokeInvokes the method methodName in time seconds.
在time秒后,延迟调用方法methodName。
InvokeRepeatingInvokes the method methodName in time seconds, then repeatedly every repeatRate seconds.
在time秒调用methodName方法,然后每repeatRate秒重复调用。
IsInvokingIs any invoke on methodName pending?
methodName方法是否在等候调用?
StartCoroutineStarts a coroutine.
开始协同程序。
StopAllCoroutinesStops all coroutines running on this behaviour.
停止运行此behaviour上的所有协同程序。
StopCoroutineStops all coroutines named methodName running on this behaviour.
停止此behaviour上运行的所有名为methodName的协同程序。

Static Functions 静态函数

printLogs message to the Unity Console (identical to Debug.Log).
输出日志消息到Unity控制台。等同Debug.Log。

Messages 消息

AwakeAwake is called when the script instance is being loaded.
当该脚本实例被载入时Awake被调用。
FixedUpdateThis function is called every fixed framerate frame, if the MonoBehaviour is enabled.
当MonoBehaviour启用时,其 FixedUpdate 在每一帧被调用。
LateUpdateLateUpdate is called every frame, if the Behaviour is enabled.
当Behaviour启用时,其LateUpdate在每一帧被调用。
OnAnimatorIKCallback for setting up animation IK (inverse kinematics).
设置动画的IK回调(反向运动学)。
OnAnimatorMoveCallback for processing animation movements for modifying root motion.
用于修改根运动处理动画移动的回调。
OnApplicationFocusSent to all game objects when the player gets or loses focus.
当玩家获得或失去焦点时发送给所有游戏对象。
OnApplicationPauseSent to all game objects when the player pauses.
当玩家暂停发送给所有游戏对象。
OnApplicationQuitSent to all game objects before the application is quit.
在应用退出之前发送给所有的游戏物体。
OnAudioFilterReadIf OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain.
如果OnAudioFilterRead被执行,Unity将插入一个自定义的过滤器到音频DSP链。
OnBecameInvisibleOnBecameInvisible is called when the renderer is no longer visible by any camera.
当renderer(渲染器)在任何相机上都不可见时调用OnBecameInvisible。
OnBecameVisibleOnBecameVisible is called when the renderer became visible by any camera.
当renderer(渲染器)在任何相机上可见时调用OnBecameVisible。
OnCollisionEnterOnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
当此collider/rigidbody触发另一个rigidbody/collider时,OnCollisionEnter将被调用。
OnCollisionEnter2DSent when an incoming collider makes contact with this object's collider (2D physics only).
当进入的碰撞器与这个对象的碰撞器接触,发送信息(仅限2D物理)。
OnCollisionExitOnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
当此collider/rigidbody停止触发另一个rigidbody/collider时,OnCollisionExit将被调用。
OnCollisionExit2DSent when a collider on another object stops touching this object's collider (2D physics only).
当另一个对象的碰撞器停止接触这个对象的碰撞器时,发送信息(仅限2D物理)。
OnCollisionStayOnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
当此collider/rigidbody触发另一个rigidbody/collider时,OnCollisionStay将会在每一帧被调用。
OnCollisionStay2DSent each frame where a collider on another object is touching this object's collider (2D physics only).
当另一个对象的碰撞器每帧接触这个对象的碰撞器时,发送信息(仅限2D物理)。
OnConnectedToServerCalled on the client when you have successfully connected to a server.
当成功连接到服务器时,在客户端调用。
OnControllerColliderHitOnControllerColliderHit is called when the controller hits a collider while performing a Move.
在移动的时,当controller碰撞到collider时OnControllerColliderHit被调用。
OnDestroyThis function is called when the MonoBehaviour will be destroyed.
当MonoBehaviour将被销毁时,这个函数被调用。
OnDisableThis function is called when the behaviour becomes disabled () or inactive.
当对象变为不可用或非激活状态时此函数被调用。
OnDisconnectedFromServerCalled on the client when the connection was lost or you disconnected from the server.
当失去连接或从服务器端断开时在客户端调用。
OnDrawGizmosImplement OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn.
如果你想绘制可被点选的gizmos,执行OnDrawGizmos。
OnDrawGizmosSelectedImplement this OnDrawGizmosSelected if you want to draw gizmos only if the object is selected.
如果你想在物体被选中时绘制gizmos,执行这个函数。
OnEnableThis function is called when the object becomes enabled and active.
当对象被启用并激活状态时此函数被调用。
OnFailedToConnectCalled on the client when a connection attempt fails for some reason.
当一个连接因为某些原因失败时在客户端调用。
OnFailedToConnectToMasterServerCalled on clients or servers when there is a problem connecting to the MasterServer.
当连接MasterServer出现问题时在客户端或服务器端调用。
OnGUIOnGUI is called for rendering and handling GUI events.
渲染和处理GUI事件时调用。
OnJointBreakCalled when a joint attached to the same game object broke.
当附在同一对象上的关节被断开时调用。
OnLevelWasLoadedThis function is called after a new level was loaded.
当一个新关卡被载入时此函数被调用。
OnMasterServerEventCalled on clients or servers when reporting events from the MasterServer.
当报告事件来自MasterServer时在客户端或服务器端调用。
OnMouseDownOnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
当用户鼠标在GUIElement或Collider上点击时OnMouseDown被调用。
OnMouseDragOnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
当用户鼠标在GUIElement或Collider上拖拽时OnMouseDrag被调用 。
OnMouseEnterOnMouseEnter is called when the mouse entered the GUIElement or Collider.
当鼠标进入到GUIElement(GUI元素)或Collider(碰撞体)中时调用OnMouseEnter。
OnMouseExitOnMouseExit is called when the mouse is not any longer over the GUIElement or Collider.
当用户鼠标不在GUIElement或Collider上时OnMouseExit被调用。
OnMouseOverOnMouseOver is called every frame while the mouse is over the GUIElement or Collider.
当用户鼠标在GUIElement或Collider上经过时OnMouseOver被调用。
OnMouseUpOnMouseUp is called when the user has released the mouse button.
当用户释放鼠标按钮时调用OnMouseUp。
OnMouseUpAsButtonOnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed.
OnMouseUpAsButton只有当鼠标在同一个GUIElement或Collider按下,在释放时调用。
OnNetworkInstantiateCalled on objects which have been network instantiated with Network.Instantiate.
当对象使用Network.Instantiate进行网络初始化时调用。
OnParticleCollisionOnParticleCollision is called when a particle hits a collider.
当粒子碰到碰撞器时,OnParticleCollision 被调用。
OnPlayerConnectedCalled on the server whenever a new player has successfully connected.
当一个新玩家成功连接时在服务器上被调用。
OnPlayerDisconnectedCalled on the server whenever a player disconnected from the server.
当一个玩家从服务器上断开时在服务器端调用。
OnPostRenderOnPostRender is called after a camera finished rendering the scene.
在相机完成场景渲染之后被调用。
OnPreCullOnPreCull is called before a camera culls the scene.
在相机消隐场景之前被调用。
OnPreRenderOnPreRender is called before a camera starts rendering the scene.
在相机渲染场景之前被调用。
OnRenderImageOnRenderImage is called after all rendering is complete to render image.
当完成所有渲染图像后被调用,用来渲染图像后期效果。
OnRenderObjectOnRenderObject is called after camera has rendered the scene.
在相机场景渲染完成后被调用。
OnSerializeNetworkViewUsed to customize synchronization of variables in a script watched by a network view.
在一个网络视图脚本中,用于自定义变量同步。
OnServerInitializedCalled on the server whenever a Network.InitializeServer was invoked and has completed.
当Network.InitializeServer被调用并完成时,在服务器上调用这个函数。
OnTriggerEnterOnTriggerEnter is called when the Collider other enters the trigger.
当Collider(碰撞体)进入trigger(触发器)时调用OnTriggerEnter。
OnTriggerEnter2DSent when another object enters a trigger collider attached to this object (2D physics only).
当另一个对象进入到这个对象附加的触发碰撞器时发送消息(仅2D物理)。
OnTriggerExitOnTriggerExit is called when the Collider other has stopped touching the trigger.
当Collider(碰撞体)停止触发trigger(触发器)时调用OnTriggerExit。
OnTriggerExit2DSent when another object leaves a trigger collider attached to this object (2D physics only).
当另一个对象离开附加在这个对象的触发碰撞器时发送消息(仅2D物理)。
OnTriggerStayOnTriggerStay is called once per frame for every Collider other that is touching the trigger.
当碰撞体接触触发器时,OnTriggerStay将在每一帧被调用。
OnTriggerStay2DSent each frame where another object is within a trigger collider attached to this object (2D physics only).
当另一个对象停留在这个对象附加的触发碰撞器内时,每帧发送消息(仅2D物理)。
OnValidateThis function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
当该脚本被加载或检视面板的值被修改时,此函数被调用(仅在编辑器被调用)。
OnWillRenderObjectOnWillRenderObject is called once for each camera if the object is visible.
如果该对象可见,OnWillRenderObject每次会被相机调用。
ResetReset to default values.
重设为默认值。
StartStart is called on the frame when a script is enabled just before any of the Update methods is called the first time.
Start仅在当第一次脚本启用Update方法被调用之前调用。
UpdateUpdate is called every frame, if the MonoBehaviour is enabled.
当MonoBehaviour启用时,其Update在每一帧被调用。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文