Unity5.1 new network engine UNET (7) UNET single player game converts to multiplayer, unity5.1unet
Single player game to multiplayer sun Guangdong
This document describes how to convert a single player to a multiplayer game using a new network system. The process described here is simplified. For a real game, it actually requires a higher-level version of the actual process. Now we are talking about not working, just like every game here, however, it provides the basic formula.
1. NetworkManager Installation
• Add a new game object to the scenario and rename it "NetworkManager ".
• Add the NetworkManager component for New Game objects.
• Add the NetworkManagerHUD component to a game object. This provides the default UI for managing the status of online games.
2. Player Prefab Installation
• Find THE player prefab in the game or create a preset from the player Object.
• Add the NetworkIdentity component to player prefab.
• Check the LocalPlayerAuthority box of NetworkIdentity.
• Set playerPrefab for "Spawn Info" on the NetworkManager component of player prefab.
• Remove the player object instance from the site if it exists in the site
3. Player Movement
• Add the NetworkTransform component to player prefab
• Update input and control scripts to comply with isLocalPlayer
• Fixed the problem where camera uses the derived player and isLocalPlayer.
For example, this script only processes the 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, instead of MonoBehaviours
• Enable important member variables to SyncVars
5. Networked Actions
• Make the script execute NetworkBehaviours important operations instead of MonoBehaviours
• Important commands used by the Update function to execute player operations
6. Non-Player Objects
Modify non-player prefabs, such as enemies:
• Add the NetworkIdentify component
• Add the NetworkTransform component
• NetworkManager registers spawnable presets
• Update scripts and game status and operations
7. Spawners
• The spawner script that may be changed must inherit from NetworkBehaviours.
• Modify spawners to run only on the server and use the isServer attribute or OnStartServer () function
• Call NetworkServer. Spawn () for the created object ()
8. Location of Player generation
• Add a new game object and place it in the position where the player should start
• Add the NetworkStartPosition component for New Game objects
9. loby
• Create lolobby Scene Create Hall site
• Import multiplayer-lolobby package Import multiplayer game hall package
• Add GuiLobbyManager preset to the scenario
• Configure the manager Configuration manager
• Scenes
• Prefabs
• Spawners
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.