This is a short course designed to introduce you to Unity's Networked Multiplayer system.
In it, we'll create a small tank arena shooter where we introduce:
We will learn how to make our simple player drive around an arena level and connect with more than one player over a network.
This is an introduction to networking concepts as well as several components specifically made for Unity Multiplayer Networking.
Note: this course is designed for Mac and PC standalone (Multiplayer over LAN Network) and does not cover mobile devices.
In this lesson, we learn how to make our player move!
Here we setup the basic components of our player and the master script, the PlayerController class, that connects them with our player input.
A tank turret isn't a turret if it can't rotate!
Build our maze, one block at a time!
We add the Network Manager, a handy component that lets us manage our networked game.
Let's see how we can make our tank movement synchronized over the network.
We label and color the tank so we can tell one player from the other.
Here we work on the Bullet and PlayerShoot scripts. Our tank isn't a tank if it can't fire giant projectiles!
We complete the Bullet and PlayerShoot scripts except for a few nagging details...
... like shooting projectiles over Networked Multiplayer! Here we also learn about spawning objects over the network and make our first networked Command remote action.
We learn that bullets can hurt us!
We add a networked synchronized variable so that our health values can be synchronized over the network using Server Authority.
Here we learn how to use a new Remote Action, the ClientRPC, which will be instrumental in making our tank die over the network.
We learn how to use the NetworkStartPosition component to spawn our player when it connects to the NetworkManager. Then we learn how to repurpose them, so we can implement re-spawing in our gameplay scripts.
We create the GameManager and make it a Singleton.
We use some coroutines to define our main game loop.
We learn to simulate a simple "lobby" to make the game wait for our players to connect.
Note: make sure that your m_playerColors array in the GameManager shows up correctly with the four different colors or else the GameManager will not properly increment the playerCount. Any colors will do but you cannot have less colors than the number of players connected.
Let's add a simple scoring mechanism. This one involves quite a few small changes to existing components: the Bullet, PlayerShoot, PlayerHealth and PlayerController scripts!
We have our scores stored with the PlayerControllers, now let's show them on the user interface.
Let's add the Game Over message with a ClientRpc.
A quick recap of what we learned today!
We create a SpawnPoint script that allows us to respawn only at unoccupied NetworkSpawnPoints.
We repair some longstanding issues with the single-player shooter mechanics, including the occasional shooting through walls or bullets that strike your own player before they leave the barrel of the gun.
In the beginning of this multi-part lesson, we import the Network Lobby asset from the Asset Store's Unity Essentials. We'll split our Project into two different scenes, the Lobby Scene (Lobby) and the Game Play Scene (Main).
We complete some basic setup to allow the new LobbyManager to replace our original NetworkManager from the previous tutorials.
In this continued lesson, we begin repairing our game now that our Network Lobby Manager has replaced the original NetworkManager. In this lesson, we should learn about:
We make adjustments to the PlayerSetup component so we can store our Lobby Player's color and name string when we launch the game.
In the next installment of adding our Network Lobby, we:
By the end of Part 4, we should have most of our game back into working order.
In this session, we:
Here we restore the scoreboard which consists of three parts:
In this final update, we configure Unity Services for Multiplayer and get our game working across the Internet. Using the Network Lobby, you can create a game session online and then players anywhere in the world can join your session and you can duke it out in the arena!
Note: there is no SavePoint for this lesson. Just configure the Multiplayer Services on your dashboard to enable the service.
This is an experiment to add multiple maps to our game.
Wilmer Lin is a 3D and visual effects artist with over fifteen years of industry experience and has trained several hundred artists over the course of a decade. Now an independent game developer, Wilmer helps aspiring gamedevs learn the craft of programming and designing video games using Unity3D, Maya and Photoshop.