Unity3D多线程

来源:互联网 发布:求不定积分的软件 编辑:程序博客网 时间:2024/05/02 04:40
using UnityEngine;
using System.Collections;
using System.Threading;
public class MyThread
{
public int count;
string thrdName;
public MyThread(string nam)
{
     count = 0;
  thrdName = nam;
}
public void run()
{
  Debug.Log("start run a thread"+Time.time);
  do{
     Thread.Sleep(1000);
     Debug.Log("in child thread"+Time.time+"count="+count);
     count++;   
   }while(count <20);
   Debug.Log("end thread"+Time.time);
}

}
public class testThread : MonoBehaviour {
// Use this for initialization
void Start () {
  Debug.Log("start main"+Time.time);
    MyThread mt = new MyThread("CHILE ");
  Thread newThrd = new Thread(new ThreadStart(mt.run));
  newThrd.Start();
}

// Update is called once per frame
void Update () {
      Debug.Log(Time.time);
}
}
0 0
原创粉丝点击