??
Single player game convert to multiplayer Sun Guangdong 2015.7.12
This document describes the steps to convert a single player game to a multiplayer game that uses a new network system. The process described here is simplified, for a real game actually requires a higher level version of the actual process, which is now introduced to not work like this in every game, but it provides the basic recipe.
1, NetworkManager Installation
? Add a new game object to the scene and rename it to "NetworkManager".
? Add the NetworkManager component to the new game object.
? Add the Networkmanagerhud component to the game object. This provides the default UI for managing the network game state.
2. Player Prefab Installation
? In the game, find player's prefab prefab, or create a preset from the player object.
? The Networkidentity component is added to the player prefab.
? Check networkidentity's localplayerauthority box.
? Set the Spawn Info setting on the NetworkManager component of the player prefab Playerprefab
? Remove the Player object instance from the scene if it exists in the field
3. Player Movement
? Add the Networktransform component to the player prefab
? Update the input and control scripts to comply with Islocalplayer
? Fixed camera using derived player and Islocalplayer
For example, this script only handles local player input:
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 }}
4. Basic Player Game State
? Make the script contain important data to networkbehaviours, not monobehaviours
? Make important member variables to Syncvars
5. Networked Actions
? Make the script perform networkbehaviours important operations instead of monobehaviours
? Important commands for the update function to perform the player operation
6, Non-player Objects
Modify non-player prefabs, such as enemies:
? Adding Networkidentify Components
? Adding Networktransform Components
? NetworkManager Register spawnable pre-built body
? Update scripts and game status and actions
7, Spawners
? Spawner scripts that may change to inherit from Networkbehaviours
? Modify Spawners to run only on the server, using the Isserver property or the Onstartserver () function
? Call Networkserver.spawn () for creating an object
8. Where the player is generated
? Add a new Game object and place it where the player should start
? New Game Object Add Networkstartposition component
9, Lobby
? Create Lobby scene Creation Hall site
? Import Multiplayer-lobby Package importing multiplayer lobby pack
? Add Guilobbymanager presets to a scene
? Configure the manager Configuration Manager
? Scenes
? Prefabs
? Spawners
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Unity5.1 new network engine unet (vii) Unet single player conversion to multiplayer