Version: 5.4
씬 오브젝트(Scene Objects)
Multiplayer Lobby

Converting a Single Player Game to Multiplayer

This document describes steps to convert a single player game to a multiplayer game using the new networking system. The process described here is a simplified, higher level version of the actual process for a real game and doesn’t work exactly like this for every game, but it provides a basic recipe for the process.

NetworkManager 설치

  • 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 will provide the default UI for managing network game state.

자세한 내용은 NetworkManager 사용를 참조하십시오.

Player Prefab Setup

  • Find the prefab for the player object in the game, or create a prefab from the player object.
  • Add NetworkIdentity component to player prefab.
  • Check the LocalPlayerAuthority box on the NetworkIdentity.
  • Set the playerPrefab in the “Spawn Info” section on the NetworkManager to the player prefab
  • Remove the player object instance from the scene if it exists in the scene

플레이어 오브젝트를 참조하십시오.

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

예를 들어, 아래 스크립트는 로컬 플레이어용 입력만을 처리합니다.

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

  • 중요한 데이터를 포함하는 스크립트는 MonoBehaviours 대신 NetworkBehaviours에 포함되도록 해야 합니다.
  • 중요한 멤버 변수는 SyncVars에 포함되도록 해야 합니다.

상태 동기화를 참조하십시오.

Networked Actions

  • 중요한 액션을 포함하는 스크립트는 MonoBehaviours 대신 NetworkBehaviours에 포함되도록 해야 합니다.
  • Update functions that perform important player actions to be Commands

네트워크 액션을 참조하십시오.

비플레이어 오브젝트

적과 같은 비플레이어 프래팹을 다음과 같이 고정해야 합니다.

  • Add NetworkIdentify component
  • Add NetworkTransform component
  • Register spawnable prefabs with NetworkManager
  • 스크립트에 게임 상태와 액션을 업데이트해야 합니다.

스포너

  • 스포너 스크립트를 NetworkBehaviour로 변환할 수 있습니다.
  • Modify spawners to only run on the server, use isServer property or OnStartServer() function
  • Call NetworkServer.Spawn() for created objects

플레이어 스폰 포지션

  • Add new game object and place at player start location
  • Add NetworkStartPosition component to new game object

로비

  • 로비 씬을 생성합니다.
  • Add a new game object to the scene and rename it to “NetworkLobbyManager”.
  • Add the NetworkLobbyManager component to the new game object.
  • Configure the manager
    • 프리팹
    • spawners
씬 오브젝트(Scene Objects)
Multiplayer Lobby