当前位置: 首页 > news >正文

004-unity3d MonoBehaviour脚本方法简介

一、MonoBehaviour

1、公共方法

CancelInvokeCancels all Invoke calls on this MonoBehaviour.
InvokeInvokes the method methodName in time seconds.
InvokeRepeatingInvokes the method methodName in time seconds, then repeatedly every repeatRate seconds.
IsInvokingIs any invoke on methodName pending?
StartCoroutineStarts a coroutine.
StopAllCoroutinesStops all coroutines running on this behaviour.
StopCoroutineStops the first coroutine named methodName, or the coroutine stored in routine running on this behaviour.

2、静态方法

printLogs message to the Unity Console (identical to Debug.Log).

3、其他方法

AwakeAwake is called when the script instance is being loaded.
FixedUpdateThis function is called every fixed framerate frame, if the MonoBehaviour is enabled.
LateUpdateLateUpdate is called every frame, if the Behaviour is enabled.
OnAnimatorIKCallback for setting up animation IK (inverse kinematics).
OnAnimatorMoveCallback for processing animation movements for modifying root motion.
OnApplicationFocusSent to all GameObjects when the player gets or loses focus.
OnApplicationPauseSent to all GameObjects when the application 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.
OnBecameInvisibleOnBecameInvisible is called when the renderer is no longer visible by any camera.
OnBecameVisibleOnBecameVisible is called when the renderer became visible by any camera.
OnCollisionEnterOnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
OnCollisionEnter2DSent when an incoming collider makes contact with this object's collider (2D physics only).
OnCollisionExitOnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
OnCollisionExit2DSent when a collider on another object stops touching this object's collider (2D physics only).
OnCollisionStayOnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
OnCollisionStay2DSent each frame where a collider on another object is touching this object's collider (2D physics only).
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.
OnDestroyThis function is called when the MonoBehaviour will be destroyed.
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.
OnDrawGizmosSelectedImplement OnDrawGizmosSelected to draw a gizmo if the object is selected.
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.
OnGUIOnGUI is called for rendering and handling GUI events.
OnJointBreakCalled when a joint attached to the same game object broke.
OnJointBreak2DCalled when a Joint2D attached to the same game object breaks.
OnMasterServerEventCalled on clients or servers when reporting events from the MasterServer.
OnMouseDownOnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
OnMouseDragOnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
OnMouseEnterCalled when the mouse enters the GUIElement or Collider.
OnMouseExitCalled when the mouse is not any longer over the GUIElement or Collider.
OnMouseOverCalled every frame while the mouse is over the GUIElement or Collider.
OnMouseUpOnMouseUp is called when the user has released the mouse button.
OnMouseUpAsButtonOnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed.
OnNetworkInstantiateCalled on objects which have been network instantiated with Network.Instantiate.
OnParticleCollisionOnParticleCollision is called when a particle hits a Collider.
OnParticleTriggerOnParticleTrigger is called when any particles in a particle system meet the conditions in the trigger module.
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.
OnTransformChildrenChangedThis function is called when the list of children of the transform of the GameObject has changed.
OnTransformParentChangedThis function is called when the parent property of the transform of the GameObject has changed.
OnTriggerEnterOnTriggerEnter is called when the Collider other enters the trigger.
OnTriggerEnter2DSent when another object enters a trigger collider attached to this object (2D physics only).
OnTriggerExitOnTriggerExit is called when the Collider other has stopped touching the trigger.
OnTriggerExit2DSent when another object leaves a trigger collider attached to this object (2D physics only).
OnTriggerStayOnTriggerStay is called once per frame for every Collider other that is touching the trigger.
OnTriggerStay2DSent each frame where another object is within a trigger collider attached to this object (2D physics only).
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 for each camera if the object is visible.
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.
UpdateUpdate is called every frame, if the MonoBehaviour is enabled.

二、继承成员

1、成员变量

enabledEnabled Behaviours are Updated, disabled Behaviours are not.
isActiveAndEnabledHas the Behaviour had enabled called.
gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

2、公共方法

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagIs this game object tagged with tag ?
GetComponentReturns the component of Type type if the game object has one attached, null if it doesn't.
GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the component of Type type in the GameObject or any of its parents.
GetComponentsReturns all components of Type type in the GameObject.
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.
GetComponentsInParentReturns all components of Type type in the GameObject or any of its parents.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the game object.

3、静态方法

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateClones the object original and returns the clone.

4、操作符

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.

相关文章:

  • JS-DOM的知识点及应用
  • 怎样做网站优化才能更有效的吸引蜘蛛来访?
  • centos--git搭建之Gogs安装
  • 记一次kafka故障
  • Visual Studio Code支持JUnit
  • “大数据应用场景”之隔壁老王(连载四)
  • vfp9写的爬虫前段,基于webbrowser
  • CSS定宽居中的实现方案
  • 思科——NAT的应用
  • Webpack3之雪碧图插件(WEBPACK-SPRITESMITH配置简述)
  • 一万元搭建深度学习系统:硬件、软件安装教程,以及性能测试
  • linux 环境变量配置(node)
  • springboot 在IDEA下启动异常问题
  • 关于Python的Object继承
  • centos6.X上安装zabbix-3.0.4和邮件设置
  • php的引用
  • AzureCon上微软宣布了哪些容器相关的重磅消息
  • es6
  • exif信息对照
  • exports和module.exports
  • Flannel解读
  • Git同步原始仓库到Fork仓库中
  • javascript 总结(常用工具类的封装)
  • java小心机(3)| 浅析finalize()
  • node-sass 安装卡在 node scripts/install.js 解决办法
  • Python 基础起步 (十) 什么叫函数?
  • Python进阶细节
  • Spring Cloud Alibaba迁移指南(一):一行代码从 Hystrix 迁移到 Sentinel
  • 短视频宝贝=慢?阿里巴巴工程师这样秒开短视频
  • 分享一份非常强势的Android面试题
  • 前端每日实战:70# 视频演示如何用纯 CSS 创作一只徘徊的果冻怪兽
  • 驱动程序原理
  • 三分钟教你同步 Visual Studio Code 设置
  • 小程序01:wepy框架整合iview webapp UI
  • Unity3D - 异步加载游戏场景与异步加载游戏资源进度条 ...
  • 阿里云服务器购买完整流程
  • 数据可视化之下发图实践
  • ​什么是bug?bug的源头在哪里?
  • #我与Java虚拟机的故事#连载16:打开Java世界大门的钥匙
  • (八)c52学习之旅-中断实验
  • (分布式缓存)Redis分片集群
  • (分享)一个图片添加水印的小demo的页面,可自定义样式
  • (附源码)spring boot基于Java的电影院售票与管理系统毕业设计 011449
  • (力扣)1314.矩阵区域和
  • (六)激光线扫描-三维重建
  • (实战篇)如何缓存数据
  • .NET 6 Mysql Canal (CDC 增量同步,捕获变更数据) 案例版
  • .NET Core WebAPI中封装Swagger配置
  • .net专家(张羿专栏)
  • 。Net下Windows服务程序开发疑惑
  • @FeignClient注解,fallback和fallbackFactory
  • @Responsebody与@RequestBody
  • [ 蓝桥杯Web真题 ]-布局切换
  • [C/C++]关于C++11中的std::move和std::forward
  • [CF226E]Noble Knight's Path