๐ Episode 8 ยท Series Finale ยท Netcode for GameObjects
Play Together! Multiplayer Basics
The finale: real networked multiplayer with Unityโs official Netcode, host and join, synced player movement, server authority, RPCs for effects, and a shared score. Two windows, one game.
2Assign it as the Default Player Prefab on the NetworkManager, NGO spawns one per connection automatically.
3Movement scripts become NetworkBehaviour and gate on IsOwner, otherwise YOUR keys move EVERY player on screen (the classic first bug, try it once, on purpose!).
using Unity.Netcode;
using UnityEngine;
public class NetPlayerMove : NetworkBehaviour
{
public float speed = 5f;
void Update()
{
if (!IsOwner) return; // only drive YOUR player!
Vector2 input = new Vector2(
Input.GetAxisRaw("Horizontal"),
Input.GetAxisRaw("Vertical")).normalized;
transform.position += (Vector3)(input * speed * Time.deltaTime);
}
}
โจ๏ธ
Code Challenge
+20 XP
Stop your keys driving everyoneโs character:
NetPlayerMove.cs
void Update()
{
if (!) ;
// ... movement ...
}
๐ก Hint: A NetworkBehaviour knows whether this instance belongs to the local player; bail out early when it does not.
๐ง
Knowledge Check
+15 XP
Without the IsOwner check, pressing W movesโฆ
ANothing
BEVERY playerโs character in your window, each copy of the script reads your keyboard
COnly the host
3
๐งช
Two Windows, One Game
Build & run alongside the editor and TEST it
Locked
๐ฏ
Goal for this step
Actually run multiplayer: a build as host, the editor as client.
1Build the game (File โ Build). Launch the .exe โ click Host.
2Press Play in the editor โ click Client. Two players appear in BOTH windows.
3Move in each window, watch the other update live. Feel that? That is the moment.
4Under the hood: your position โ serialized โ sent over the transport โ applied remotely, ~50 times a second, both directions.
5This build+editor workflow is how you will test all networking from now on.
๐ก
Seeing your own game run networked for the first time is a top-five gamedev moment. Screenshot both windows. You earned it.
โ๏ธ
Fill in the Blanks
+15 XP
The standard test loop is a running as host with the joining as client. NetworkTransform syncs position roughly times per second.
๐ง
Knowledge Check
+15 XP
Why test with a build + editor instead of two editors?
AEditors cannot connect
BOne project opens once, build+editor is the fastest honest two-instance test on one machine
CBuilds are prettier
4
๐ข
NetworkVariables: Shared State
A synced score that all players see
Locked
๐ฏ
Goal for this step
Share game state correctly with NetworkVariable.
1Shared values live in NetworkVariable<T>, the server writes, everyone reads, sync is automatic.
2A ScoreBoard NetworkBehaviour: NetworkVariable<int> score; only the server may change it (authority!).
3Clients react via OnValueChanged, update the UI text when the value arrives.
4Add collectable coins (server-spawned NetworkObjects): a player touching one โ the SERVER destroys it and bumps score. One truth, no arguments.
ScoreBoard.cs
using Unity.Netcode;
using TMPro;
public class ScoreBoard : NetworkBehaviour
{
public NetworkVariable<int> score = new NetworkVariable<int>(0);
public TMP_Text label;
public override void OnNetworkSpawn()
{
score.OnValueChanged += (oldVal, newVal) =>
label.text = "Score: " + newVal;
}
public void AddPoint()
{
if (!IsServer) return; // authority!
score.Value += 1;
}
}
โ๏ธ
Fill in the Blanks
+15 XP
Synced state lives in a , which only the writes. Clients update UI through its callback.
๐ง
Knowledge Check
+15 XP
The if (!IsServer) return; guard in AddPoint enforcesโฆ
AFrame rate
BServer authority, a client calling it does nothing; only the truth-owner may change the score
CFaster syncing
5
๐ฃ
RPCs: Making Things Happen
ServerRpc requests, ClientRpc broadcasts
Locked
๐ฏ
Goal for this step
Use RPCs for actions and effects across the network.
2ServerRpc: a client asks the server to do something ("I pressed the emote button!"). Method name MUST end in ServerRpc.
3ClientRpc: the server tells all clients to show something ("play the confetti on player 2!").
4The full loop: client presses E โ EmoteServerRpc() โ server validates โ EmoteClientRpc() โ every screen shows the emote. Request up, broadcast down, that is 90% of multiplayer gameplay code.
PlayerEmote.cs
using Unity.Netcode;
using UnityEngine;
public class PlayerEmote : NetworkBehaviour
{
void Update()
{
if (IsOwner && Input.GetKeyDown(KeyCode.E))
EmoteServerRpc();
}
[ServerRpc]
void EmoteServerRpc()
{
EmoteClientRpc(); // server approves & broadcasts
}
[ClientRpc]
void EmoteClientRpc()
{
// runs on EVERY client:
Instantiate(confettiPrefab, transform.position,
Quaternion.identity);
}
}
Assemble a 2-player coin-race and close out the series.
1Assemble the pieces: synced players โ server-spawned coins โ NetworkVariable scores (one per player or a simple shared board) โ a win banner via ClientRpc at 10 coins โ.
2Playtest with a friend on your LAN (same network: host shows their local IP in the transport, client enters it).
3Series retrospective, you now hold: components & prefabs, physics, animation state machines, coroutines, UI/persistence, scenes, and networked authority. That is a professional Unity foundation.
4The engine is yours now. Build the game only YOU would make. ๐ท
๐ก
Multiplayer ideas that fit your current skills: co-op coin race, competitive breakout (two paddles!), tag, a tiny arena shooter. Small + finished beats big + abandoned.
โ๏ธ
Fill in the Blanks
+15 XP
Coins must be spawned by the so it owns their truth. The win announcement reaches every screen through a .
๐ง
Knowledge Check
+15 XP
Eight Unity episodes done. The deepest lesson of the multiplayer finale wasโฆ
ANetworking is impossible
BAuthority: decide WHO owns each piece of truth and all of multiplayer falls into place
CRPCs are named weirdly
๐๐๐ฎโจ๐
Workshop Complete!
Host, client, sync, authority, RPCs, eight episodes from Pong to networked multiplayer. You are a Unity developer, full stop. ๐ท๐