It is best to first make a mini practice game before converting your single player game, or creating your ideal brand new multiplayer.
The Pre-made Mirror examples are great for using as reference, it is recommend to use them regarding connection setup, with ports and firewalls. This can be a huge topic that changes from person to person, and is not covered in this guide, here we will use localHost (multiple games on same PC).
## Part 1
Blank Project, import Mirror from [Asset Store](https://assetstore.unity.com/packages/tools/network/mirror-129321).
## Part 2
- Create new scene, save it, and add it to build settings
- Create a new GameObject, name it NetworkManager in the scene, and add these 3 components
- NetworkManager
- TelepathyTransport
- NetworkManagerHUD
- On the NetworkManager component, drag your Offline and Online scene into the slots, we have only one scene
for now, so put your scene in both
- The scene must be in the build settings before dragging it to the field
![](./image--000.jpg)
![](./image--001.jpg)
## Part 3
Setup the scene
- Add a simple Plane floor with:
- positions (0, -1, 0)
- scale (2, 2, 2)
- (optional) add a material to this, I added one called dirt that is used one of mirrors examples
- Next we add a GameObject, name does not matter
- Add `NetworkStartPosition` component to this GameObject
- Duplicate the GameObject a few times, and scatter around your scene floor so that you have multiple spawn points. I did 4, one near each corner
![](./image--002.jpg)
## Part 4
Creating the player
- Create a capsule using the menus as shown in the image
- Attached a NetworkTransform component, this will auto add a Network Identity
- Tick Client Authority on the NetworkTransform
![](./image--003.jpg)
- Rename that object Player
- Add an empty PlayerScript
- Drag into Project to create a prefab
- Then delete Player from scene
![](./image--004.jpg)
- Drag your player prefab into Network manager,
- Set spawn method to Round Robin.
![](./image--005.jpg)
## Part 5
Add the following to your PlayerScript.
```cs
using Mirror;
using UnityEngine;
namespace QuickStart
{
public class PlayerScript : NetworkBehaviour
{
public override void OnStartLocalPlayer()
{
Camera.main.transform.SetParent(transform);
Camera.main.transform.localPosition = new Vector3(0, 0, 0);
Press play in Unity editor, and then Host (server + client) button in the game window. You should be able to move around with a first person view capsule.
![](./image--006.jpg)
## Part 7
Build and run your scene, open it, host on one, and press the Client button on the other. Congrats you made a mini multiplayer game!
![](./image--007.jpg)
## Part 8
Player name above heads
- Inside your player Prefab, create an empty GameObject
- name it something like `FloatingInfo`
- position Y to 1.5
- scale X to -1
- Inside that `FloatingInfo`, create a 3D text using Unity menu (GameObject - 3D Object - 3D Text),
- Set it up as shown in the picture below
![](./image--008.jpg)
## Part 9
Update your PlayerScript.cs with this:
```cs
using Mirror;
using UnityEngine;
namespace QuickStart
{
public class PlayerScript : NetworkBehaviour
{
public TextMesh playerNameText;
public GameObject floatingInfo;
private Material playerMaterialClone;
[SyncVar(hook = nameof(OnNameChanged))]
public string playerName;
[SyncVar(hook = nameof(OnColorChanged))]
public Color playerColor = Color.white;
void OnNameChanged(string _Old, string _New)
{
playerNameText.text = playerName;
}
void OnColorChanged(Color _Old, Color _New)
{
playerNameText.color = _New;
playerMaterialClone = new Material(GetComponent<Renderer>().material);
Here we will make a small adjustment, as using a GameObject.Find() may not guarantee Network Identity scene objects are found.
In the image below you can see our NetworkIdentity scene object gets disabled, as they are disabled until a player is in ‘ready’ status (ready status is usually set when player spawns).
![](./image--021.jpg)
So our chosen workaround is to have our GameObject.Find() get the non-networked scene object, which will have those Network Identity scene object as pre-set variables.
Create a new script called SceneReference.cs, and add this one variable.
Menu and Scene switching, here we will go from an offline Menu, with a play button, to a Games List with a back button and the Host/Join HUD, to your online map, and then a second map for host to switch to.
Open up SceneScript.cs and add the following function.
```cs
public void ButtonChangeScene()
{
if (isServer)
{
Scene scene = SceneManager.GetActiveScene();
if (scene.name == "MyScene") { NetworkManager.singleton.ServerChangeScene("MyOtherScene"); }
Duplicate your previous Canvas button, rename it and reposition it, then setup the OnClick() to point to SceneScript.ButtonChangeScene, like in the image.
Then drag your NetworkManager into your Project, to make it a Prefab, this way any changes we make later will apply to them all.
If you haven’t already, you can sort out your project into folders, one for scripts, prefabs, scenes, textures etc. :)
![](./image--024.jpg)
## Part 17
Save, and then Duplicate your MyScene, rename to make a Menu, GamesList and MyOtherScene, then add them to the build settings, with Menu being first.
![](./image--025.jpg)
Open up the Menu scene, remove the spawn points, SceneScript, SceneReference, Network Manager and Plane, so it looks like the below.
Adjust the canvas button to say Play, centre it.
Here is where you could add the Scores scene, Contact section, News, etc
Create a Menu.cs script, add it onto a Menu gameObject.
![](./image--026.jpg)
Add the code to Menu.cs, then in the Button, drag the Menu gameobject into the On Click () and set it to Menu.LoadScene, like in the picture.
Open up GamesList scene, do similar to Menu but KEEP NetworkManager prefab.
Create a GamesList.cs, add the code, and add it onto a GamesList gameobject in the scene.
Adjust a canvas button to say Menu (this is our back button). It should look like the image below.
- The games list is where you can add List server contents, or matchmaker, or just the host and join buttons, similar to the default NetworkManagerHud, for now leave this. :)
Change the camera background colour and floor material (or anything, just so you can see both scenes are different.
To summarise, MyScene is map 1 and MyOtherScene is map 2.
![](./image--029.jpg)
In your NetworkManager prefab in PROJECT (not the one in scenes), add Menu to offline, and MyScene to Online variables. This should change all the NetworkManager prefabs to have these settings.
![](./image--030.jpg)
Build and Run, press Play on the Menu to go to GamesList, then click Host (for player 1).
For player 2, press Play on Menu, then client connect on GamesList.
Now the host can change scenes between map 1 and map 2, and if anyone disconnects or stops the game, Menu scene is load to start again.
This whole process can be tidied up, but should provide a good scene switch template to your Mirror game :)
## Part 20
Here we will add basic weapon firing, using rigidbody prefabs.
Raycasts with a representation of the fired object is usually better to do this, and keep phycisal objects for things like Grenades and Cannon balls.
This section will also lack a lot of security and ant-cheat techniques in order to keep the guide simple, but anyway, here we go!
Double click the Player Prefab to open it, create empty gameobjects and line them up with the end of your weapon, add them as child to each weapon.
Some weapons may be short pistols, others long rifles, so the place where objects spawn will be different.
![](./image--031.jpg)
Create a Weapon.cs script, add it to the Weapon1 and Weapon 2 gameObjects inside the player prefab.
Now back in your scene we shall make 2 bullets, in Unitys menu, go to GameObject, 3D Object, Sphere.
Add rigidbody to this sphere, make the scale 0.2, 0.2, 0.2, then save it as a Prefab in the Project.Do the same with a cube, so you have two different looking bullets.
![](./image--032.jpg)
Inside your player prefab again, select a weapon, and set the variables on weapon script.
![](./image--033.jpg)
![](./image--034.jpg)
## Part 22
In SceneScript.cs, add this variable and function.
```cs
public Text canvasAmmoText;
public void UIAmmo(int _value)
{
canvasAmmoText.text = "Ammo: " + _value;
}
```
Enter MyScene (map 1).
Duplicate the Canvas StatusText, rename to Ammo, then drag that Ammo text UI into SceneScript gameobject, canvasAmmoText variable.
Do this on BOTH MyScene (map 1) and MyOtherScene (map 2), as we have not yet linked or prefabbed our canvas and scene scripts to auto update changes on each map.
![](./image--035.jpg)
Open up PlayerScript.cs, add these two variables:
```cs
private Weapon activeWeapon;
private float weaponCooldownTime;
```
In the ‘OnWeaponChanged’ function, update it with the new line, so it should look like this.