Today using unity to meet a big pit

Source: Internet
Author: User

Let's sum up today's harvest: When initializing a member variable in a script class, when in awake (), when it is in Start () is fastidious.

1) When a member variable is referenced by an external script, especially if the member variable is a self -defined non-scripting class that must be initialized with a constructor . Also, an external script reference refers to "when an internal member function or property referencing the variable is called by an external function ", and the member variable should be initialized in the awake function.

2) If the member variable is referenced only in the script class where it is located, it should be initialized in the start function.

The pit we met today was due to not noticing the above two points. I initialized a poker class with a constructor in the start function, but an instance of this class was called by an external script in its own public method. This is not the most important, because I met once before. It is important to copy the preset in the update () function, whose awake () function is immediately called in the update of the current frame , but the start () function is executed at the next frame .

Today using unity to meet a big pit

Related Article

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.