Setting up the Player prefab

版本检查: 5.3


难度: 中级

The Player prefab asset will represent the player, or players, in this example project.

By default, the NetworkManager component instantiates a GameObject for each player that connects to the networked game by cloning the player prefab and spawning the clone into the game.

Network Spawning and the details of synchronizing player GameObjects over the Clients and Server will be covered later in this assignment.

For this example, the player GameObject will be a simple Capsule with a “visor” so we know which way the capsule is facing.

The final Player GameObject in the scene should look like this.


To create this Player GameObject:

  • Create a new Capsule primitive GameObject.
  • Rename the new GameObject to “Player”

To indicate the “front” of the Player GameObject, so we know which way it is facing, add a small Cube to the Player GameObject as a child and color it black.

  • With the Player GameObject selected,
  • ... create a new Cube primitive GameObject as a child of the Player GameObject.
  • Rename the new GameObject “Visor”.
  • Set the Visor GameObject’s Scale to (0.95, 0.25, 0.5).
  • Set the Visor GameObject’s Position to: (0.0, 0.5, 0.24).
  • Create a new Material.
  • Name this Material “Black”.
  • With the Black Material selected,
  • ... change the Albedo color of the Material to black.
  • Set the Visor GameObject’s Material to the Black Material .

To identify the Player as a unique Networked GameObject, add a NetworkIdentity to the Player.

  • With the Player GameObject selected,
  • ... find and add the component: Network > NetworkIdentity.

The NetworkIdentity component is used to identify the object on the Network and to make the Networking system aware of it. For more information on the NetworkIdentity component, please see the page on NetworkIdentity.

  • Set the Local Player Authority checkbox on the NetworkIdentity to true.


Setting the NetworkIdentity to Local Player Authority will allow the Client to control the movement of this Player GameObject.

Create a prefab from the Player GameObject

  • Drag the Player GameObject into the Project window to create a new prefab asset.
  • Delete the Player GameObject from the scene.
  • Save the scene.

For more information on setting up player GameObjects, please see the page on Player Objects.