Multiplayer is everywhere. It's a staple of AAA games and small-budget indie offerings alike. Multiplayer games tap into our most basic human desires. Whether it be teaming up with strangers to survive a zombie apocalypse, or showing off your skills in a round of "Capture the Flag" on your favorite map, no artificial intelligence in the world comes close to the feeling of playing with a living, breathing, and thinking human being.
Unity3D has a sizable number of third-party networking middleware aimed at developing multiplayer games, and is arguably one of the easiest platforms to prototype multiplayer games.
The first networking system most people encounter in Unity is the built-in Unity Networking API. This API simplifies a great many tasks in writing networked code by providing a framework for networked objects rather than just sending messages. This works by providing a NetworkView component, which can serialize object state and call functions across the network.
Additionally, Unity provides a Master server, which essentially lets players search among all public servers to find a game to join, and can also help players in connecting to each other from behind private networks.
In this chapter, we will cover:
Introducing multiplayer
Introducing UDP communication
Setting up your own Master server for testing
What a NetworkView is
Serializing object state
Calling RPCs
Starting servers and connecting to them
Using the Master server API to register servers and browse available hosts
Setting up a dedicated server model
Loading networked levels
Creating a Pong clone using Unity networking