Legacy Documentation: Version 2018.2 (Go to current version)
Networking HLAPI System Concepts
Player GameObjects
Other Versions

Networked GameObjects

Networked GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
are GameObjects which are controlled and synchronized by Unity’s networkingThe Unity system that enables multiplayer gaming across a computer network. More info
See in Glossary
system. Using synchronized networked GameObjects, you can create a shared experience for all the players who are playing an instance of your game. They see and hear the same events and actions - even though that may be from their own unique viewpoints within your game.

Multiplayer games in Unity are typically built using ScenesA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
that contain a mix of networked GameObjects and regular (non-networked) GameObjects. The networked GameObjects are those which move or change during gameplay in a way that needs to be synchronized across all users who are playing the game together. Non-networked GameObjects are those which either don’t move or change at all during gameplay (for example, static obstacles like rocks or fences), or GameObjects which have movement or changes that don’t need to be synchronized across players (for example, a gently swaying tree or clouds passing by in the background of your game).

A networked GameObject is one which has a Network Identity component attached. However, a Network Identity component alone is not enough for your GameObject to be functional and active in your multiplayer game. The Network Identity component is the starting point for synchronization, and it allows the Network ManagerA Networking component that manages the network state of a Project. More info
See in Glossary
to synchronize the creation and destruction of the GameObject, but other than that, it does not specify which properties of your GameObject should be synchronized.

What exactly should be synchronized on each networked GameObject depends on the type of game you are making, and what each GameObject’s purpose is. Some examples of what you might want to synchronize are:

  • The position and rotation of moving GameObjects such as the players and non-player characters.

  • The animation state of an animated GameObject

  • The value of a variable, for example how much time is left in the current round of a game, or how much energy a player has.

Some of these things can be automatically synchronized by Unity. The synchronized creation and destruction of networked GameObjects is managed by the NetworkManager, and is known as Spawning. You can use the Network Transform component to synchronize the position and rotation of a GameObject, and you can use the Network Animator component to synchronize the animation of a GameObject.

To synchronize other properties of a networked GameObject, you need to use scripting. See State Synchronization for more information about this.

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答