Answer the question
In order to leave comments, you need to log in
How to convert JSONObject to string on Unity with socket.io?
Hello. There is a client and server part. I send data from the server and I want an action to take place on the client based on this data.
Server
var player = {
x: 25,
y: 10,
z: 22
}
socket.emit('spawn', {xCoords:player.x,yCoords:player.y,zCoords:player.z});
void Start(){
socket = GetComponent<SocketIOComponent>();
socket.On("spawn", onSpawn);
}
void onSpawn(SocketIOEvent e){
string playerX = e.data.GetField("xCoords").toString();
Instantiate(playerPrefab);
}
Answer the question
In order to leave comments, you need to log in
https://docs.unity3d.com/ScriptReference/JsonUtili...
make first json by format. pass exactly Json
{"xCoords":"player.x","yCoords":"player.y","zCoords":"player.z"} from the server - for example, if you want to transfer strings.
Here you can check that everything is parsed correctly.
well, then it’s easier - work with jison as it says in the documentation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question