Posted on

PUN 2 in Unity: Make a Game Multiplayer Lesson 2

For this lesson, we will be setting up the matchmaking for our multiplayer game. To do this quickly we will be using our PUN 2 Matchmaking Add-on. You can also build your own version of this plugin by following our tutorial series. You will only need to create the QuickStart system.

Once you have access to the add-on we will then need to import it into Unity. Open up your pong project then go Assets > Import Package > Custom Package. You will then need to find the location you saved the QuickStart Unity Package and open it up. This will then open the import window for which you can leave everything selected and click Import.

You should now have a few new files and folders in your project window. In your project window, goto InfoGamerAssets > PUN2_Matchmaking > Prefab > QuickStart and drag the PhotonQuickStart prefab into the hierarchy of your main menu scene.

Now you need to disable your old canvas object and make your new canvas, which is a child to the new QuickStart prefab, look like the old canvas. The easiest way to do that is to select the various objects that make up our old canvas such as the title then go over to one of its components click on the gear icon in the top-right corner and select copy component. Then go to the corresponding objects of our new canvas and go to the same component and click on the gear icon then select paste component values. repeat this step until the new canvas looks like the old canvas. For the three-button objects that are part of the new canvas you want to copy the appearance of the button but leave the button component alone.

  • Canvas
    • QuickStartMenu – turn the alpha channel of the Image component down to zero.
      • – Text should read Pong and should look like the old title.
      • – resize and make the button image transparent.
        • Text – Set best fit to be active.
      • – resize and make the button image transparent.
        • Text – Set best fit to be active.
      • – resize and make the button image transparent.
        • Text – Set best fit to be active.

Now there are a few more things that we need to do before we can test our project the first is that we need to set the room size of our multiplayer game. To do this select the quickStartLobbyController object and then you need to set the room size variable and just set it to 2.

The next thing that we need to do is set up our game scene for networking to do this we’re going to load into our game scene. We then need to go to the prefabs folder of our matchmaking add-on and select the gameSetup prefab and drag it into our hierarchy.

Now you should be able to test your project. Load back into your main menu scene. As you play your project you should be able to click the play button of your game and load into the game scene. If you now see a capsule object in the middle of your scene then everything should be working.