Unity3d the meaning of the script's activation and disabling and the explanation of the check box disappears before the script

Source: Internet
Author: User


Hello, I'm a little panda.

Reprint Please specify source: http://blog.csdn.net/a237653639/article/details/45766101


First summary, then prove.

Summarize:

The purpose of disabling the script is to make the script "not executed", and the purpose of enabling it is to "execute" the script. The above is my original idea, in fact, this understanding is biased. To be precise, even if the script is disabled, other scripts can successfully invoke the members of the disabled script ( It will be shown later . ).


So, you might ask, what's the point of disabling the script?

in fact, the meaning is that When a script is enabled, Unity automatically calls the script's class to inherit from the Monobehaviour method, whereas unity does not invoke these methods when the script is disabled. It does not affect the invocation of other scripts to members within the script .


Prove:

even if the script is disabled, other scripts can successfully invoke members of the disabled script

Step 1, create a cube first, and then hang a test script on it. Then hang a Test2 script on the Maincamera.

We will disable the test script, and Test2 will invoke the member in test.

Such as:

Cube

Camera


The contents of the test script are:

The contents of Test 2 are:

Note that we have set the test script to Disabled.

Now, we see the results of the run, such as. Cube. Getcomponent<test> (). Print () was successfully invoked, but the update method inherited from monobehaviour in test was not called.


now to explain that the check box in front of the script disappears Reason:

First of all, the check box disappears because I first copy and paste the explanation of the rain pine great God:

All the scripts do not have tick options, because your script does not have the Start method. If you want the check box to appear,

Add the following method, do not believe you can try. Hey. someone tested it,

Plus Update lateupdate fixedupdate Ongui can also make the check box come out ... But awake not.

Through the explanation of the great God of the rain, the following is my further idea.

through the above summary, we already know: when the script is enabled,

Unity automatically calls the script's class to inherit from the Monobehaviour method,

Conversely, unity does not invoke these methods when the script is disabled.

My thoughts are:

If your script does not have a way to inherit from Monobehaviour, it means you don't need unity to call it (there is no, where to call it).

in this case, your script is disabled regardless of or if it's enabled, it's not a half-penny relationship with unity,

so Unity doesn't show you the check box, because it's not necessary. and once there is a succession such as start (actually overwrite)

Monobehaviour method, this is the unity of the horse! So the check box will be displayed again,

You control whether unity is allowed to invoke the Start method. What about awake?  

i awake is called once and just like the constructor. ),

If you re-enable a script, the AW in the script The Ake method is not called, and the Start method will function again (called).

Awake is invoked only once when its script-attached object is first created (regardless of whether the script is enabled or disabled

are called once) and are no longer called. So "Awake" (Can't make the check box appear again), haha.

Speaking of which, do you understand?? ^_^

Unity3d the meaning of the script's activation and disabling and the explanation of the check box disappears before the script

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.