unity3d 多線程 三行代碼 秒懂

多線程代碼:

using System.Collections;
using System.Threading;
using Unity.Collections;
using UnityEngine;

public class MyThread : MonoBehaviour
{
    void Start()
    {
        // 多線程
        // 指定線程要運行的程序(函數)
        ThreadStart threadStart = new ThreadStart(MyThreadFun);
        // 創建多線程對象
        Thread thread = new Thread(threadStart);
        // 運行多線程
        thread.Start();
    }
    void MyThreadFun()
    {
        for (int i = 0; i < 100; i++)
        {
            Debug.Log("我是多線程:" + i);
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章