I have the following code:
socket.On ("chat", (data) => {
string str = data.ToString ();
ChatData chat = JsonConvert.DeserializeObject<ChatData> (str);
string strChatLog = "user#" + chat.id + ": " + chat.msg;
int pos = userArr.IndexOf (chat.id);
if (pos > -1) {
var InsObj = Instantiate (player, StringToVector3 (chat.msg), Quaternion.identity);
InsObj.name = chat.id;
userArr [userArr.Length + 1] = chat.id;
}
// Access to Unity UI is not allowed in a background thread, so let's put into a shared variable
lock (chatLog) {
chatLog.Add (strChatLog);
}
});
When I try to run it I get this error:
Assets/SocketIO/SocketIOScript.cs(59,23): error CS1593: Delegate `System.Action' does not take `1' arguments
However when I remove this part :
int pos = userArr.IndexOf (chat.id);
if (pos > -1) {
var InsObj = Instantiate (player, StringToVector3 (chat.msg), Quaternion.identity);
InsObj.name = chat.id;
userArr [userArr.Length + 1] = chat.id;
}
It works just fine.
I am wondering why this is happening, I have been trying to figure it out for quite a while. I found this post about it, but that did not help me much, because I don't think that I can specify data
.
EDIT:
StringToVector3
contains the following code (However even if I get rid of StringToVector3
I still get the error):
public static Vector3 StringToVector3 (string sVector)
{
// Remove the parentheses
if (sVector.StartsWith ("(") && sVector.EndsWith (")")) {
sVector = sVector.Substring (1, sVector.Length - 2);
}
// split the items
string[] sArray = sVector.Split (',');
// store as a Vector3
Vector3 result = new Vector3 (
float.Parse (sArray [0]),
float.Parse (sArray [1]),
float.Parse (sArray [2]));
return result;
}