Contents - Quick Links
- 1Unity multiplayer tutorial, physics calculations on server
- 2Creating the pong field
- 3Creator and Proxy prefab and adding components
- 4Creating and adding the Inputs components to enable player control
- 5Creating the Server and the Client connection logic
- 6Implementing the ball
- 7Building the game .exe and Unity full project download
Creating the Server and the Client connection logic
This part of this Unity multiplayer tutorial with physics calculations on server will focus on the server and client logic, we will write two scripts attached to empty gameobjects to define the roles of the client and the server scene.
- Open the pongserver scene. In the scene, create an empty gameobject and name it Server.
- In the Scripts folder create a new C# script named ServerLogic, we will code the instantiation of the three prefabs on the server and on the client and manage the player’s spawn points.
ServerLogic.cs – Unity multiplayer tutorial physics on server C# script code example download
- Add the ServerLogic script as a component to the Server game object in the pongserver scene.
- The Server game object needs another component to actually make the server starting, a uLink Simple Server script, add it to the Server from Component->uLink Utilities->Simple Server and set its maximum connection option to 2.
The code written in the ServerLogic script will handle player connection and instantiation. We will need to code the connection logic in the client to advance in this unity multiplayer tutorial.
- Open the pongclient scene, then create a new empty gameobject and name it Client.
- Add to it as a component the uLink Client GUI script, it will enable a mask that will let connect the client, you must click to connect to lacalhost once strated the server.
- Save the scene and the project, we successfully implemented player rackets log on and motion. If you build one .exe with the server scene and one exe with the client scene only you can test the logon and the motion implementation, you should see the racket on the client moving a little late respect to the server, this i wanted to take care of latency issues.
Next step in this Unity multiplayer tutorial with physics calculated on the authoritative server will be covering the ball implementation, we need a ball to score a goal in pong !!