以前我們都是用javascript開發unity的,但是我今天才發現個問題,那就是javascript裡面沒有線程。沒辦法我只能用C#了,其實C#和java才不多的,有我們的線程,下面我就舉個簡單的例子來說明一下吧;
- using UnityEngine;
- using System.Collections;
- using System.Threading;
- public class move1: MonoBehaviour {
- void Start () {
- MyThread mt = new MyThread("thread");
- Thread newnewThrd = new Thread(new ThreadStart(mt.run));
- newThrd.Start();
- }
- void Update(){}
-
- }
- public class MyThread
- {
- public int count;
- string thrdName;
- public MyThread(string nam)
- {
- count = 0;
- thrdName = nam;
- }
- public void run()
- {
- Debug.Log(thrdName);
- }
-
- }
我也不說多的了,C#我也還沒學過,還好學過了java了,大家一定要記得加using system.Threading哦~~~。