Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Closeid | Message type ID number. |
msg | Message structure. |
void True if message is sent.
Send given message structure as an unreliable message.
#pragma strict public class MyMsgTypes { public static var MSG_LOGIN: short = 51; public static var MSG_START: short = 52; } public class LoginMessage extends System.ValueType { public var myName: String; } class GameClient { var myClient: NetworkClient; GameClient { myClient = new NetworkClient(); myClient.Connect("localhost", 55555); myClient.RegisterHandler(MsgType.SYSTEM_CONNECT, OnConnected); } public function OnConnected(conn: NetworkConnection, reader: NetworkReader) { myClient.Ready(); var msg: LoginMessage; msg.myName = "SomeGuy"; myClient.SendUnreliable(MyMsgTypes.MSG_LOGIN, msg); } }
using UnityEngine; using UnityEngine.Networking;
public class MyMsgTypes { public static short MSG_LOGIN = 51; public static short MSG_START = 52; };
public struct LoginMessage { public string myName; }
class GameClient { NetworkClient myClient;
GameClient() { myClient = new NetworkClient(); myClient.Connect("localhost", 55555);
myClient.RegisterHandler(MsgType.SYSTEM_CONNECT, OnConnected); }
public void OnConnected(NetworkConnection conn, NetworkReader reader) { myClient.Ready();
LoginMessage msg; msg.myName = "SomeGuy";
myClient.SendUnreliable(MyMsgTypes.MSG_LOGIN, msg); } }