Posted on

Unity Multiplayer – Quick Start

This is the second lesson in this Unity multiplayer tutorial series. In this lesson, we will teach you how to make a quick start matchmaking system. This will allow the player to click one single button which will then load them into a multiplayer match.

Unity UI setup for Quick Start

In this tutorial, we will begin by creating the UI for our quick start matchmaking. For this UI in Unity, we will need three UI buttons. One of the buttons we will disable the interactable option of the button, this will be for before we connect to the Photon servers. The second button will be our join or quick-start button and the third button will be a cancel button. We will need to hide these last two buttons in the hierarchy. Once we create these button we will need to create a new script which will be for this quick start mechanic.

Coding Quick Start Matchmaking in C#

In this new C# script, we will need to first create a callback function for when our play first connects to the Photon servers. in this callback function, we want to enable the quick-start button. We will then need to create a public function that we can pair to the On Click of the quick-start button. In this function, we need to make it so that the players first try to join an existing game but if no game is available then we will try to create a new game. When we successfully join or create a new room we will then load the players into the game scene and instantiate a player object in the scene for each player. We then need to create another public function, that will be for the cancel button.

Working in Unity

Once you have this script created, we will then go back to Unity. In Unity, we will need to create an empty game object to attach this script to. We will then need to set the value of our variables and you will need to set the on click functions of the various buttons. Next, you will need to create a player prefab object. Finally, we will need to create a new scene to be our multiplayer game scene.

Testing your Project

If you followed along with this tutorial you should then have a working quick start matchmaking system for your game. When you test your project you will know the quick start is working when you see two instances of your game load into the multiplayer scene and in the hierarchy, you can see two different player prefabs with each being owned by a different user.

Unlock Code and Member Content