[Unet] How to Use SendBytesToPlayer?
Hey guys!
Trying to use the SendBytesToPlayer() to send a serialized class to a specific player, but i dont get how to trigger a function on the other side to receive the data? can't see any example on the unity manual so i came here!
Need this:
Choose a destination player/connection
Choose an specific Network Channel Id
Am trying something like this, but idk what to do next?
public void SendSocketMessage(GameObject playerObj) {
CubeListMessage msg = new CubeListMessage();
msg.resourcePosition = resourcePosition;
msg.resourceRotation = resourceRotation;
msg.resourceType = resourceType;
msg.resourceColor = resourceColor;
msg.resourceColor2 = resourceColor2;
msg.resourceColor3 = resourceColor3;
byte error;
byte[] buffer = new byte[1024];
Stream stream = new MemoryStream(buffer);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, msg);
int bufferSize = 1024;
NetworkServer.SendBytesToPlayer(playerObj,buffer, bufferSize, 1);
}
Answer by seanr · Aug 31, 2015 at 01:14 PM
Use a network message instead:
http://docs.unity3d.com/Manual/UNetMessages.html
I need to send a message that have these conditions: specific player or a connection to send to & specific CHANNEL ID, can you give me an example that have those?
gameObject.GetComponent< NetworkIdentity>().connectionToClient.SendByChannel()
Good, if it is not aloot to ask, could you make a simple example sending and receiving that message, on your /\ Answer so i can accept it? Thanks!
Your answer
Follow this Question
Related Questions
"SerializationException: Unexpected binary element: 0" on Deserialization of struct 0 Answers
Ordering reliable and unreliable messages in UNET 1 Answer
Netcode - Exception: Type Unity.Collections.FixedString32Bytes is not serializable 0 Answers
How to serialize a List of ContentPacks (from Morph3D) in Photon Unity Networking? 0 Answers
Handling serialization of Transform (Unity / Mirror networking) 0 Answers