Posted on

Instantiating Player Avatars with Photon 2 in Unity

For this Unity Multiplayer Game Tutorial on how to make a multiplayer game in Unity with the Photon 2 Plugin, we will teach you how to spawn a player avatar or character. This will be an object that the players can control and use to play the game. This Avatar could be a person in a first-person shooter or a hero dungeon crawler RPG like Diablo 3. It is very important that you keep the Avatar as a sperate object the first photon network player object that is already spawned into the multiplayer scene.

We will begin by looking at how our game currently works. Our game currently has the Photon Player object that is the only object in our scene that is associated with our players because of this we need to make sure that we maintain this player object through the duration of our multiplayer game.

We will first create a new C# script in Unity we will call this C# script Photon Player. In this script, we need to include the Photon.PUN namespace we will then create some variable is this script including a Photon View variable. This script will be in charge of instantiating our player’s avatar object into the multiplayer scene.

In Unity, we need to create some empty game objects to be our spawn points transforms. We then need to create a player avatar prefab. We will need to set the variables of our scripts.

If you followed along with the video, you should have a working multiplayer game that allows you to instantiate new player avatar objects into the scene.