Version: 2019.3
The Network Manager HUD in Matchmaker mode
Debugging Information

Converting a single-player game to Unity Multiplayer

Note: UNet is deprecated, and will be removed from Unity in the future. A new system is under development. For more information and next steps see this blog post and the FAQ.

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.

NetworkManager set-up

  • Add a new GameObject to the Scene and rename it “NetworkManager”.
  • Add the NetworkManager component to the “NetworkManager” GameObject.
  • Add the NetworkManagerHUD component to the GameObject. This provides the default UI for managing the network game state.

Ver Utilizando el NetworkManager.

Player Prefab set-up

  • Find the Prefab for the player GameObject in the game, or create a Prefab from the player GameObject
  • 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
  • Remove the player GameObject instance from the Scene if it exists in the Scene

See Player Objects for more information.

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

Por ejemplo, este script solamente procesa input para el jugador local:

using UnityEngine;
using UnityEngine.Networking;

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

  • Cree scripts que contengan datos importantes en NetworkBehaviours en vez de MonoBehaviours
  • Cree variables miembro importantes a SyncVars

Ver Sincronización de estado.

Networked actions

  • Cree scripts que realicen acciones importantes en NetworkBehaviours en vez de MonoBehaviours
  • Update functions that perform important player actions to be commands

Ver acciones en Red.

Non-player GameObjects

Arregle prefabs no-jugador como lo son enemigos:

  • Add the NetworkIdentify component
  • Add the NetworkTransform component
  • Register spawnable Prefabs with the NetworkManager
  • Actualice scripts con el estado de juego y acciones

Generadores (spawners)

  • Potencialmente cambie scripts generadores a que sean NetworkBehaviours
  • Modify spawners to only run on the server (use isServer property or the OnStartServer() function)
  • Call NetworkServer.Spawn() for created GameObjects

Spawn positions for players

  • Add a new GameObject and place it at player’s start location
  • Add the NetworkStartPosition component to the new GameObject

Lobby

  • Cree una escena Lobby
  • Add a new GameObject to the Scene and rename it to “NetworkLobbyManager”.
  • Add the NetworkLobbyManager component to the new GameObject.
  • Configure the Manager:
    • Escenas
    • Prefabs
    • Spawners
The Network Manager HUD in Matchmaker mode
Debugging Information