In terms of network, I like to write it in the form of C/S, but the official example is in the form of peer-to-peer. I am readingOfHourThen we encountered a problem. Next let's take a lookCodeIt was written in the form of C/S. It was changed by referring to the official example.
1. Server: the server is responsible for generating servers. The code is very simple and the same as that in the chat room.
2.Client: it is also very simple. It just connects to the server, and then adds a code that instantiates a game object when the connection to the server is successful. Add a cube prefab prefabrication on the client end, add a networkview to the Cube prefabrication, And then pre-fabricate the cube to control the movement of the code segment.
Buy on behalf of the following:
Public var playerprefab: transform; function onconnectedtoserver () {spawnplayer ();} function spawnplayer () {var mynewtrans: Transform = network. instantiate (playerprefab, transform. position, transform. rotation, 0);} function onplayerdisconnected (Player: networkplayer) {debug. log ("Clean up after player" + player); network. removerpcs (player); network. destroyplayerobjects (player);} function ondisconnectedfromserver (Info: networkdisconnection) {debug. log ("clean up a bit after server quit"); network. removerpcs (network. player); network. destroyplayerobjects (network. player); application. loadlevel (application. loadedlevel );}
3. Open the server, open the two customer service terminals, and have two objects in the two customer service terminals respectively (the objects are overlapped and you can see them when you move one object in the same customer service end)
4. I found that many errors occurred these days due to the synchronization of networkview and repeated port numbers. If you have any problems, you can try these two aspects. In addition, when the client is forcibly disconnected, when the client connects to the server again, there will be one more client than all clients, so we 'd better not force the disconnection. If the client has been forcibly disconnected, well, you can change the port number again.
5. I will write more data interaction information as I study it. Make progress together ~~~~ QQ: 397319689 (a bit stupid )~~~