Creating A Multiplayer Game Using Mirror
Creating A Multiplayer Game Using Mirror
Multiplayer Game
using Mirror
First let’s setup a Mirror to be use in creating multiplayer
game, by opening unity and create a new project
void Start()
{
// Find the main camera in the scene
mainCamera = Camera.main;
}
void Update()
{
if (!isLocalPlayer)
return;
In the Start method, initialize the objectRenderer variable and apply the
initial properties:
Handling Property Changes with Hooks
Implement hook methods to handle changes to color and shape properties:
Changing Object Shape
Implement the ChangeShape method to update the object's shape based on the
shape index:
Synchronizing Property Changes Across Network
Implement methods to change color and shape on the server and client:
Implementing Remote Procedure Calls (RPCs)
Implement RPC methods to synchronize color and shape changes
across clients:
Attach the script to the cube and also add a Network Identity
component to it
In the Interactable Script change the Sync Direction to
“Client To Server”
Now to test it, at the top bar of unity you’ll see a parrel sync
click it and choose clone manager this section will appear. Add
a new clone, this will clone your unity projects and open
automatically
Your project and the clone must be open at the same time to
test it. Now hit play on both project and choose host to the
first project and client to the clone project.
In host server when clicked space it will change the color of the
cube.
In client server the shape of the cube change.
That’s it. You’ve completed all the necessary steps in creating
multiplayer game using Mirror.
Thank You!