The use of the threads in unity and considerations

Source: Internet
Author: User

  Cutting edge: This chapter will briefly summarize how to open a process, close the process, and use the co-process considerations.

first, how to open the co-process:
Private voidStart () {M_sphereprefab= Resources.load<gameobject> ("test/sphere_00"); Debug.Log ("M_sphereprefab ="+M_sphereprefab); #regionStudy and use of the association processStartcoroutine (test_00 ()); Startcoroutine ("test_01"); Startcoroutine (test_02 (5,9)); #endregion    }    PrivateIEnumerator test_00 () {Debug.Log ("co-test_00 ready to execute"); yield return NewWaitforseconds (3.0f); Debug.Log ("The test_00 execution of the co-process is complete"); }    PrivateIEnumerator test_01 () {Debug.Log ("co-test_01 ready to execute"); yield return NewWaitforseconds (5.0f); Debug.Log ("The test_01 execution of the co-process is complete"); }    PrivateIEnumerator test_02 (intAintb) {Debug.Log ("co-test_02 ready to execute"); yield return NewWaitforseconds (8.0f); Debug.Log ("co-process test_02:"+ A +" "+b); Debug.Log ("The test_02 execution of the co-process is complete"); }

    Here, there are 3 ways to open a process, and how to use the data in a co-process.

Second, how to stop the co-process
Private voidUpdate () {if(M_currentcount <M_maxcount) {            if(Time.time >m_nextclonetime) {                //CloningClone (); }        }        if(Input.getkeyup (keycode.t)) {//when you stop the Stopcoroutine by using the method name , you need to use the method name to start the process.//How to stop the error//Stopcoroutine (test_00 ());        }        if(Input.getkeyup (keycode.y)) {//when you stop the Stopcoroutine by using the method name , you need to use the method name to start the process.//the right way to stopStopcoroutine ("test_01"); }        if(Input.getkeyup (keycode.u)) {stopallcoroutines (); }    }

    Here, the method for stopping the association is indicated.

Third, the matters needing attention

    1. If you stop a specified association (stopcoroutine), the parameters should be the method name, and when the process is opened, the parameters should be the method name.

2. When using Stopallcoroutines to stop the process, it should be noted that instead of stopping all the threads, all the threads under the current script are stopped.

The use of the threads in unity and considerations

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.