Android+Unity游戏开发之C#线程


以前我们都是用javascript开发unity的,但是我今天才发现个问题,那就是javascript里面没有线程。没办法我只能用C#了,其实C#和java才不多的,有我们的线程,下面我就举个简单的例子来说明一下吧;

  1. using UnityEngine;  
  2. using System.Collections;  
  3. using System.Threading;  
  4. public class move1: MonoBehaviour {  
  5.  void Start () {  
  6.     MyThread mt = new MyThread("thread");  
  7.     Thread newnewThrd = new Thread(new ThreadStart(mt.run));  
  8.     newThrd.Start();  
  9.  }   
  10.  void Update(){}  
  11.   
  12. }  
  13. public class MyThread  
  14. {  
  15.    public int count;  
  16.    string thrdName;  
  17.   public MyThread(string nam)  
  18.   {  
  19.      count = 0;  
  20.      thrdName = nam;  
  21.   }  
  22.   public void run()  
  23.   {  
  24.      Debug.Log(thrdName);  
  25.   }  
  26.   
  27. }  

我也不说多的了,C#我也还没学过,还好学过了java了,大家一定要记得加using system.Threading哦~~~。

相关内容