Sending/receiving messages
Once connected to a room, we have a connection that can be used to send and receive messages. Let's register event handlers for receiving messages, as well as disconnections.
First, we'll add methods to handle these events:
// called when we've disconnected from the room void OnDisconnect( object sender, string message ) { Debug.Log( "Disconnected from room" ); } // called when a message is received void OnMessage( object sender, Message e ) { }
Then we'll modify our OnGUI
method to hook up these event handlers upon connection:
void OnGUI() { if( roomConnection != null ) return; if( GUILayout.Button( "Join Random", GUILayout.Width( 200f ) ) ) { client.Multiplayer.CreateJoinRoom( "$service-room$", "MyCode", true, null, null, delegate( Connection connection ) { Debug.Log( "Joining room" ); roomConnection = connection; roomConnection.OnMessage += new MessageReceivedEventHandler( OnMessage ); roomConnection.OnDisconnect...