2018-12-26 22:07:24 +00:00
# Getting Started
This document describes steps to converting a single player game to a multiplayer game, using the new Unity Multiplayer networking system. The process described here is a simplified, higher level version of the actual process for a real game; it doesn’ t always work exactly like this, but it provides a basic recipe for the process.
2019-11-28 15:29:29 +00:00
## Video tutorials
Check out these [awesome videos ](https://www.youtube.com/playlist?list=PLkx8oFug638oBYF5EOwsSS-gOVBXj1dkP ) showing you how to get started with mirror. Courtesy of [First Gear Games ](https://www.youtube.com/channel/UCGIF1XekJqHYIafvE7l0c2A ) also known as Punfish in discord.
2018-12-26 22:07:24 +00:00
## NetworkManager set-up
2019-07-07 05:48:00 +00:00
- Add a new game object to the Scene and rename it “NetworkManager”.
- Add the NetworkManager component to the “NetworkManager” game object.
- Add the NetworkManagerHUD component to the game object. This provides the default UI for managing the network game state.
2019-01-09 00:40:43 +00:00
2019-08-27 12:26:41 +00:00
See [Using the NetworkManager ](../Components/NetworkManager.md ).
2018-12-26 22:07:24 +00:00
## Player Prefab
2019-07-07 05:48:00 +00:00
- Find the Prefab for the player game object in the game, or create a Prefab from the player game object
2018-12-26 22:07:24 +00:00
- Add the NetworkIdentity component to the player Prefab
- Check the LocalPlayerAuthority box on the NetworkIdentity
- Set the `playerPrefab` in the NetworkManager’ s Spawn Info section to the player Prefab
2019-07-07 05:48:00 +00:00
- Remove the player game object instance from the Scene if it exists in the Scene
2018-12-26 22:07:24 +00:00
2019-09-17 15:42:25 +00:00
See [Player Objects ](../Guides/GameObjects/SpawnPlayer.md ) for more information.
2018-12-26 22:07:24 +00:00
## Player movement
- Add a NetworkTransform component to the player Prefab
- Update input and control scripts to respect `isLocalPlayer`
- Fix Camera to use spawned player and `isLocalPlayer`
For example, this script only processes input for the local player:
2019-08-27 12:26:41 +00:00
``` cs
2018-12-26 22:07:24 +00:00
using UnityEngine;
using Mirror;
public class Controls : NetworkBehaviour
{
void Update()
{
if (!isLocalPlayer)
{
// exit from update if this is not the local player
return;
}
// handle player input for movement
}
}
```
## Basic player game state
- Make scripts that contain important data into NetworkBehaviours instead of MonoBehaviours
- Make important member variables into SyncVars
2019-09-21 03:34:03 +00:00
See [State Synchronization ](../Guides/Sync/index.md ).
2018-12-26 22:07:24 +00:00
## Networked actions
- Make scripts that perform important actions into NetworkBehaviours instead of MonoBehaviours
- Update functions that perform important player actions to be commands
2019-09-17 15:42:25 +00:00
See [Networked Actions ](../Guides/Communications/index.md ).
2018-12-26 22:07:24 +00:00
2019-07-07 05:48:00 +00:00
## Non-player game objects
2018-12-26 22:07:24 +00:00
Fix non-player prefabs such as enemies:
- Add the NetworkIdentify component
- Add the NetworkTransform component
- Register spawnable Prefabs with the NetworkManager
- Update scripts with game state and actions
## Spawners
- Potentially change spawner scripts to be NetworkBehaviours
- Modify spawners to only run on the server (use isServer property or the `OnStartServer()` function)
2019-07-07 05:48:00 +00:00
- Call `NetworkServer.Spawn()` for created game objects
2018-12-26 22:07:24 +00:00
## Spawn positions for players
2019-07-07 05:48:00 +00:00
- Add a new game object and place it at player’ s start location
- Add the NetworkStartPosition component to the new game object