UNITY GAME DEVELOPMENT
Multiplayer Networking
CLASS OVERVIEW
 Class 12 Revision
 UNet Deprication
 Server Client Model
 NetworkManager
 NetworkManagerHUD
 NetworkBehaviour
 NetworkIdentity
 isLocalPlayer, isServer
 NetworkTransform
 NetworkTransformChild
 NetworkAnimator
 [Command]
 [ClientRpc]
REVISION
 Team Collaboration
 Source Control
 SourceTree & BitBucket
 Create a Repository
 Setting up Unity for Source Control
 Creating a .gitignore file
 Commit, Push & Pull
 Creating a First Person Camera
 Movement with First Person Camera
 Shooting
 Inverse Kinematics (IK)
 Weapon Recoil
 Shoot effects & Bullet impacts
 Crouching
 Additional features
UNET DEPRICATION
 “UNet, Unity’s legacy multiplayer solution, does not meet the needs of many
multiplayer game creators.”
 “To reach the performance, scale, and security goals ofUnity creators, we’ve reached
the difficult decision that completely new technology is required,
including lightweight and fast networking, and a dedicated game server model.”
 More info:
https://support.unity3d.com/hc/en-us/articles/360001252086-UNet-Deprecation-FAQ
SERVER CLIENT MODEL
 Client sends commands (input to Server)
 Server handles commands & synchronizes everything across all clients.
NETWORKMANAGER
 The Network Manager is a component for managing the networking
aspects of a multiplayer game.
 The Network Manager features include:
 Game state management
 Spawn management
 Scene management
 Debugging information
 Matchmaking
 Customization
 More info: https://docs.unity3d.com/Manual/UNetManager.html
NETWORKMANAGERHUD
 The Network Manager HUD (“heads-up display”) provides the basic functions so
that people playing your game can start hosting a networked game, or find and
join an existing networked game.
 Unity displays the Network Manager HUD as a collection of simple UI buttons in
the Game view.
 More info: https://docs.unity3d.com/Manual/UNetManagerHUD.html
NETWORKBEHAVIOUR
 NetworkBehaviour scripts work with GameObjects that have a Network
Identity component.
 These scripts can perform high-level API functions such as Commands,
ClientRPCs, SyncEvents and SyncVars.
 With the server-authoritative system of the Unity Network System, the server
must use the NetworkServer.Spawn function to spawn GameObjects with
Network Identity components.
 Spawning them this way assigns them a NetworkInstanceId and creates them on
clients connected to the server.
 More info: https://docs.unity3d.com/Manual/class-NetworkBehaviour.html
NETWORKIDENTITY
 The Network Identity component is at the heart of the Unity networking high-
level API.
 It controls a GameObject’s unique identity on the network, and it uses that
identity to make the networking system aware of the GameObject.
 More info: https://docs.unity3d.com/Manual/class-NetworkIdentity.html
ISLOCALPLAYER, ISSERVER
 isLocalPlayer =This returns true if this object is the one that represents the player
on the local machine.
 isServer =True if this object is running on the server, and has been spawned.
NETWORKTRANSFORM
 The Network Transform component synchronizes the movement and rotation
of GameObjects across the network.
 Note that the network Transform component only synchronizes spawned
networked GameObjects.
 More info: https://docs.unity3d.com/Manual/class-NetworkTransform.html
NETWORKTRANSFORMCHILD
 The NetworkTransform Child component synchronizes the position and rotation
of the child GameObject of a GameObject with a NetworkTransform component.
 You should use this component in situations where you need to synchronize an
independently-moving child object of a Networked GameObject.
 To use the NetworkTransform Child component, attach it to the same parent
GameObject as the NetworkTransform, and use the Target field to define which
child GameObject to apply the component settings to.
 You can have multiple NetworkTransform Child components on one parent
GameObject.
 More info: https://docs.unity3d.com/Manual/class-NetworkTransformChild.html
NETWORKANIMATOR
 The Network Animator component allows you to synchronize animation states
for networked objects. It synchronizes state and parameters from
an AnimatorController.
 Note that if you create a Network Animator component on an empty
GameObject, Unity also creates a Network Identity component and
an Animator component on that GameObject.
 More info: https://docs.unity3d.com/Manual/class-NetworkAnimator.html
[COMMAND]
 Commands are sent from player objects on the client to player objects on the
server.
 For security, Commands can only be sent fromYOUR player object, so you cannot
control the objects of other players.
 To make a function into a command, add the [Command] custom attribute to it,
and add the “Cmd” prefix.
 This function will now be run on the server when it is called on the client.
 Any arguments will automatically be passed to the server with the command.
 More info: https://docs.unity3d.com/Manual/UNetActions.html
[CLIENTRPC]
 ClientRpc calls are sent from objects on the server to objects on clients.
 They can be sent from any server object with a NetworkIdentity that has been
spawned.
 Since the server has authority, then there no security issues with server objects
being able to send these calls.
 To make a function into a ClientRpc call, add the [ClientRpc] custom attribute to
it, and add the “Rpc” prefix.
 This function will now be run on clients when it is called on the server. Any
arguments will automatically be passed to the clients with the ClientRpc call.
 More info: https://docs.unity3d.com/Manual/UNetActions.html
Q&A
 Do you have any questions related to the topics mentioned?

Unity Class 13 Presentation - .

  • 1.
  • 2.
    CLASS OVERVIEW  Class12 Revision  UNet Deprication  Server Client Model  NetworkManager  NetworkManagerHUD  NetworkBehaviour  NetworkIdentity  isLocalPlayer, isServer  NetworkTransform  NetworkTransformChild  NetworkAnimator  [Command]  [ClientRpc]
  • 3.
    REVISION  Team Collaboration Source Control  SourceTree & BitBucket  Create a Repository  Setting up Unity for Source Control  Creating a .gitignore file  Commit, Push & Pull  Creating a First Person Camera  Movement with First Person Camera  Shooting  Inverse Kinematics (IK)  Weapon Recoil  Shoot effects & Bullet impacts  Crouching  Additional features
  • 4.
    UNET DEPRICATION  “UNet,Unity’s legacy multiplayer solution, does not meet the needs of many multiplayer game creators.”  “To reach the performance, scale, and security goals ofUnity creators, we’ve reached the difficult decision that completely new technology is required, including lightweight and fast networking, and a dedicated game server model.”  More info: https://support.unity3d.com/hc/en-us/articles/360001252086-UNet-Deprecation-FAQ
  • 5.
    SERVER CLIENT MODEL Client sends commands (input to Server)  Server handles commands & synchronizes everything across all clients.
  • 6.
    NETWORKMANAGER  The NetworkManager is a component for managing the networking aspects of a multiplayer game.  The Network Manager features include:  Game state management  Spawn management  Scene management  Debugging information  Matchmaking  Customization  More info: https://docs.unity3d.com/Manual/UNetManager.html
  • 7.
    NETWORKMANAGERHUD  The NetworkManager HUD (“heads-up display”) provides the basic functions so that people playing your game can start hosting a networked game, or find and join an existing networked game.  Unity displays the Network Manager HUD as a collection of simple UI buttons in the Game view.  More info: https://docs.unity3d.com/Manual/UNetManagerHUD.html
  • 8.
    NETWORKBEHAVIOUR  NetworkBehaviour scriptswork with GameObjects that have a Network Identity component.  These scripts can perform high-level API functions such as Commands, ClientRPCs, SyncEvents and SyncVars.  With the server-authoritative system of the Unity Network System, the server must use the NetworkServer.Spawn function to spawn GameObjects with Network Identity components.  Spawning them this way assigns them a NetworkInstanceId and creates them on clients connected to the server.  More info: https://docs.unity3d.com/Manual/class-NetworkBehaviour.html
  • 9.
    NETWORKIDENTITY  The NetworkIdentity component is at the heart of the Unity networking high- level API.  It controls a GameObject’s unique identity on the network, and it uses that identity to make the networking system aware of the GameObject.  More info: https://docs.unity3d.com/Manual/class-NetworkIdentity.html
  • 10.
    ISLOCALPLAYER, ISSERVER  isLocalPlayer=This returns true if this object is the one that represents the player on the local machine.  isServer =True if this object is running on the server, and has been spawned.
  • 11.
    NETWORKTRANSFORM  The NetworkTransform component synchronizes the movement and rotation of GameObjects across the network.  Note that the network Transform component only synchronizes spawned networked GameObjects.  More info: https://docs.unity3d.com/Manual/class-NetworkTransform.html
  • 12.
    NETWORKTRANSFORMCHILD  The NetworkTransformChild component synchronizes the position and rotation of the child GameObject of a GameObject with a NetworkTransform component.  You should use this component in situations where you need to synchronize an independently-moving child object of a Networked GameObject.  To use the NetworkTransform Child component, attach it to the same parent GameObject as the NetworkTransform, and use the Target field to define which child GameObject to apply the component settings to.  You can have multiple NetworkTransform Child components on one parent GameObject.  More info: https://docs.unity3d.com/Manual/class-NetworkTransformChild.html
  • 13.
    NETWORKANIMATOR  The NetworkAnimator component allows you to synchronize animation states for networked objects. It synchronizes state and parameters from an AnimatorController.  Note that if you create a Network Animator component on an empty GameObject, Unity also creates a Network Identity component and an Animator component on that GameObject.  More info: https://docs.unity3d.com/Manual/class-NetworkAnimator.html
  • 14.
    [COMMAND]  Commands aresent from player objects on the client to player objects on the server.  For security, Commands can only be sent fromYOUR player object, so you cannot control the objects of other players.  To make a function into a command, add the [Command] custom attribute to it, and add the “Cmd” prefix.  This function will now be run on the server when it is called on the client.  Any arguments will automatically be passed to the server with the command.  More info: https://docs.unity3d.com/Manual/UNetActions.html
  • 15.
    [CLIENTRPC]  ClientRpc callsare sent from objects on the server to objects on clients.  They can be sent from any server object with a NetworkIdentity that has been spawned.  Since the server has authority, then there no security issues with server objects being able to send these calls.  To make a function into a ClientRpc call, add the [ClientRpc] custom attribute to it, and add the “Rpc” prefix.  This function will now be run on clients when it is called on the server. Any arguments will automatically be passed to the clients with the ClientRpc call.  More info: https://docs.unity3d.com/Manual/UNetActions.html
  • 16.
    Q&A  Do youhave any questions related to the topics mentioned?