嘿我正在使用tcp协议使用带有循环的新线程进行多人游戏,以检查是否有要接收的消息
Thread ctThread = new Thread(getMessage);
ctThread.Start();
private void getMessage()
{
while (true)
{
int buffSize = 0;
byte[] inStream = new byte[10025];
buffSize = mySocket.ReceiveBufferSize;
theStream.Read(inStream, 0, buffSize);
try
{
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
checkMessage(returndata);
}
catch { }
}
}
每件事情都运行良好但是当我从服务器回复消息以更改活动画布或类似的东西时:
cnv.SetActive(false);
我收到此错误:
SetActive can only be called from the main thread.
而不仅仅是SetActive几乎与我得到相同的错误