Event Functions

Event Functions

  A key concept in games programming is that of making changes to position, state and behavior of objects in the game just before each frame is rendered. The Update function is the main place for this kind of code in Unity. Update is called before the frame is rendered and also before animations are calculated.

  Event Functions

  The physics engine also updates in discrete time steps in a similar way to the frame rendering. A separate event function called FixedUpdate is called just before each physics update. Since the physics updates and frame updates do not occur with the same frequency, you will get more accurate results from physics code if you place it in the FixedUpdate function rather than Update.

  Event Functions

  The LateUpdate function can be used to make additional changes at a point after the Update and FixedUpdate functions have been called for all objects in the scene and after all animations have been calculated. An example is where a camera should remain trained on a target object

  Event Functions

Initialization Events

  The Awake function is called for each object in the scene at the time when the scene loads. Note that although the various objects‘ Start and Awake functions are called in arbitrary order, all the Awakes will have finished before the first Start is called.

GUI events

  You can detect mouse events that occur over a GameObject as it appears in the scene. This can be used for targetting weapons or displaying information about the character currently under the mouse pointer. A set of OnMouseXXX event functions (eg, OnMouseOverOnMouseDown) is available to allow a script to react to user actions with the mouse. For example, if the mouse button is pressed while the pointer is over a particular object then an OnMouseDown function in that object‘s script will be called if it exists.

Physics events

  The physics engine will report collisions against an object by calling event functions on that object‘s script. The OnCollisionEnterOnCollisionStay and OnCollisionExitfunctions will be called as contact is made, held and broken. The corresponding OnTriggerEnterOnTriggerStay and OnTriggerExit functions will be called when the object‘s collider is configured as a Trigger (ie, a collider that simply detects when something enters it rather than reacting physically). These functions may be called several times in succession if more than one contact is detected during the physics update and so a parameter is passed to the function giving details of the collision (position, identity of the incoming object, etc).

 

Event Functions

上一篇:ubuntu下图形程序自启动的几种方法


下一篇:做好代码复用不简单(1)