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.
playerPrefab
in the NetworkManager’s Spawn Info section to the player PrefabSee Player Objects for more information.
isLocalPlayer
isLocalPlayer
For example, this script only processes input for the local player:
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
}
}
See Networked Actions.
Fix non-player prefabs such as enemies:
OnStartServer()
function)NetworkServer.Spawn()
for created GameObjects