So I have this code that when a socket receives data from a .net socket server it will set the position of a game object according to the data received. Well for some odd reason random question marks (?) keep showing up in my code even though I set stuff back to null nowhere in my code does it ever add question marks though. Commas yes but no question marks.
using UnityEngine;
using System.Collections;
public class moveCharacterObject : MonoBehaviour {
public static string locationString;
// Use this for initialization
void Start () {
locationString = null;
}
// Update is called once per frame
void Update () {
if(locationString != null && locationString != ""){
string[] pos = locationString.Split(',');
print(locationString);
int index = int.Parse(pos[0]);
float x = float.Parse(pos[1]);
float y = float.Parse(pos[2]);
float z = float.Parse(pos[3]);
GameObject player = GameObject.Find("player" + index.ToString());
//CharacterController controller = (CharacterController)player.GetComponent(typeof(CharacterController));
//controller.Move(new Vector3(x, y, z));
player.transform.position = new Vector3(x, y, z);
locationString = null;
}
}
}
print displays:
0,1361.38,4.530814,1367.424?1361.38,4.059223,1367.424?1361.38,3.601118,1367.424?1361.38,3.154214,1367.424
when it should only generate 4 fields, the first field is the index, defined on the server, the second field is the x, third is the y, and the final is the z. Here is how it’s being defined on the server:
index.ToString() + “,” + data
and data is defined on the client as x + “,” + y + “,” + z
any ideas?