Unity5.1 new network engine unet (vii) Unet single player conversion to multiplayer

Source: Internet
Author: User

??

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.