This is just a concluding video for you How to Make a Multiplayer Game in Unity Using the Photon Plugin tutorial series. If you are watching this video and just now joined us, start this series from the beginning. If you have finished this series then go on to our next follow up series.
Category: Basic
Disconnecting Players and Host Migration with Photon 2 in Unity
For this Tutorial lesson on how to make a Unity multiplayer video game in Unity 3D using the Photon 2 Plugin, we will be teaching you how to disconnect players for the multiplayer game that we have created. We will also show you how to handle the event of a different player leaving ht e game and finally we will talk about host migration. Host migration is when the master client is disconnected from the game and another master client must take over the connects.
The first thing we will do is open our Game Setup C# script in this script we will create a public disconnect function that we can then pair to a UI Button. This function will disconnect our player and then return us to the main menu scene.
If you followed along with the video you should now have a working game that allows the player to connect and disconnect to a multiplayer room.
Updated Video
Old Video
RPC in FPS with Photon 2 in Unity
For this tutorial lesson, on how to make a multiplayer game in Unity using the Photon 2 plugin we will be using the RPC functions we have learned about to make a basic first-person shooter control that will sync across the network. This tutorial will teach you how to use the RPC function of the Photon 2 plugin in other scenarios. After this lesson, you should have a better understanding of RPC function and what they can do as well when to use them. You will also learn how to take any game machinic and make it work in a multiplayer game.
We will begin by creating variables in our Avatar setup script for the first one will be player health and the next one will be player damage. We will then create a new C# script called Avatar Combat. In this script, we will create some new variables. We will then initialize these variables. We will then create a shooting function and we will use Raycast to do this. We first want to check for player input and then we will create our Raycast. If the Raycast hit another player then we want to remove health from that player. We will then save our C# script and go back to Unity.
In Unity, we will create and add a new camera to our player avatar object. We then need to attach our new scripts to their respective objects and set the variables.
We will then go back to our Avatar combat script and we will turn this script into a script that will work across the network. We will do this by creating an RPC function that will synchronize the player’s health across the network when the player has been shot.
If you followed along with the video then you should now have a working basic FPS controller that networks the player’s health when shot.