Unity3d-The inheritance mechanism of the Functions of the beginner's story Event

Source: Internet
Author: User

We know that event functions such as Start () Update () are called sequentially in the unity main thread. The order of calls can be found in the manual.

Some changes will also occur with this inheritance mechanism.

Test One:
 Public class mytest2:monobehaviour{    void  Start () {        //Eventdelegate.add ( Tween.onfinished, Test, true);        Debug.Log ("");    }     void Update ()    {        Debug.Log ("");}    }

 Public class mytest3:mytest2{    // Use this for initialization    void  Start ()    { C10/>debug.log ("");    }         void Update ()    {        Debug.Log ("");}    }

Run:

Test Two:

So what happens if the MyTest3 start Update is commented out.

 Public classmytest2:monobehaviour{voidStart () {//Eventdelegate.add (tween.onfinished, Test, true);Debug.Log ("MyTest2 Start"); }    voidUpdate () {Debug.Log ("MyTest2 Update"); }} Public classmytest3:mytest2{//Use this for initialization//void Start ()//{    //Debug.Log ("MyTest3 Start"); //}        //void Update ()//{    //Debug.Log ("MyTest3 Update"); //}}

Run:

Familiar with C # knows that no modifiers are private by default. It seems that unity has a special handle on this kind of function.

Test Three:

So let's look at other inheritance features.

 Public classmytest2:monobehaviour{//virtual or abstract members cannot be private     Public Virtual voidStart () {//Eventdelegate.add (tween.onfinished, Test, true);Debug.Log ("MyTest2 Start"); }    voidUpdate () {Debug.Log ("MyTest2 Update"); }} Public classmytest3:mytest2{//Use this for initialization     Public Override voidStart () {Debug.Log ("MyTest3 Start"); }    voidUpdate () {Debug.Log ("MyTest3 Update"); }}

The result appears to be the same as the test one. In other words, you will find the final instantiation of there is no, and then find the parent class has no.

Unity3d-The inheritance mechanism of the Functions of the beginner's story Event

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.