• 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.

      

      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.

      

      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

      

    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).

     

  • 相关阅读:
    HTML连载29-div和span标签
    Java连载14-补码简介&浮点型整数
    Java连载13-整数型字面值的强制转换
    Java连载12-继承开发环境&long类型
    [Python] tkinter 之 Listbox & Combobox
    [Python] Tkinter command
    [java] 转型
    [Python] execl读写
    [c++] 细节
    [刷题] PTA 7-64 最长对称子串
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3536852.html
Copyright © 2020-2023  润新知