我有这门课。
public class UploadData: MonoBehaviour{
public void uploadindividualshot(pushdatawrapper pw){
StartCoroutine (PushData (pw));
Thread t = new Thread(new ThreadStart(StartCoroutine(PushData(pw))));
t.Start();
t.IsBackground = true;
}
private IEnumerator PushData(pushdatawrapper pdata){
WWW www;
Hashtable postHeader = new Hashtable();
postHeader.Add("Content-Type", "application/json");
string dataToJason = JsonUtility.ToJson(pdata);
Debug.Log ("dataToJason " + dataToJason);
// convert json string to byte
var formData = System.Text.Encoding.UTF8.GetBytes(dataToJason);
www = new WWW("http://rmotion.rapsodo.com/api/push/new", formData, postHeader);
return www;
}
IEnumerator WaitForRequest(WWW data)
{
yield return data; // Wait until the download is done
if (data.error != null)
{
Debug.Log("There was an error sending request: " + data.text);
}
else
{
Debug.Log("WWW Request: " + data.text);
}
}
}
我在 Thread t = new Thread(new ThreadStart(StartCoroutine(PushData(pw))));
处出错,因为 Expression 表示一个 value',其中一个
类型' 或“方法组”是预期的。
如何解决这个问题?
最佳答案
忘记你想做什么,即使你摆脱了你的错误,你会在协程启动后立即抛出另一个错误,这是因为 Unity 是线程安全的,你不能在主线程之外使用 Unity 特定的 API(矢量除外如果没记错的话)。您有 2 个选择。
- 只使用一个没有线程的协程。
- 使用线程但避免使用 Unity API,例如使用 WebClient 类
关于c# - 表达式表示 `value' ,其中在 Unity 的线程内调用 StartCoroutine 时预期为 `type' 或 `method group',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50072951/