Devlog #07 - Multiplayer Battle Mode Implemented
Introduction:
As per the next plan, we'd have to convert the code made for single-player to work in multiplayer mode.
This could be easily done by making some minor changes.
PhotonView component:
The first step of this is to add photon view and photon transform view to all the components that are required to sync across the server the game is played

And then we'd have to move all the prefabs that are instantiated to a folder called "Resources", hence photon can access it easily.

Converting the Scripts:
The conversion is done by changing the following:
Firstly, check if you are accessing only your own script. This can be done by using
if (!PV.IsMine) return; if (!isAlive) return;
is alive is a bool, and is kept only for the reason to not trigger these script functions after the player is dead
Instantiate -> PhotonNetwork.Instantiate
Example:
Projectile newProjectile = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", projectilePrefab.name), projectileStartPoint.position, projectileStartPoint.rotation).GetComponent<Projectile>();
Destroy -> PhotonNetwork.Destroy
Example:
if (PV != null && PV.IsMine) { PhotonNetwork.Destroy(gameObject); }
We are checking if the function that triggers the destroy is ours because the photon network can only destroy a local player's game object, or the destroy should be done by the master client.
And whatever functions that the other client could make our client do, should be called using an RPC (Remote Procedural Call).
Defining an RPC function is done by -
[PunRPC] void DestroySelf() { if (PV != null && PV.IsMine) { PhotonNetwork.Destroy(gameObject); } }
Function call for the respective function -
if (PV.IsMine) { Debug.Log($"[{ActorId}] Player Died"); PV.RPC(nameof(DestroySelf), RpcTarget.All); }
By doing the above steps to the other function, I have successfully converted a single-player to multiplayer
Final Output:
Fixing the gun model floating by:
Since we instantiated a gun on a child, and photon networks only apply the destroy on the root model, we were required to make the gun model on the model rather than as a child that is instantiated separately. This was also completely unnecessary to instantiate it separately, since we are going to use a single gun throughout the game.
Since we removed the separate instantiation, the bug where the gun was floating after a player's death was fixed.
References:
[1] Photon PUN. Instantiation: https://doc.photonengine.com/pun/current/gameplay/instantiation
[2] Photon PUN.RPCs and RaiseEvent: https://doc.photonengine.com/pun/current/gameplay/rpcsandraiseevent
Dice & Domination
Party board game
Status | In development |
Author | Akhil Mathew |
Genre | Strategy |
More posts
- Devlog #08 - Implementing Spectator PlayerApr 29, 2025
- Devlog #06 - Implementing Enemy TurretApr 23, 2025
- Devlog #05 - Implementing Health and Damage SystemApr 17, 2025
- Devlog #04 - Implementing Shooting [Part-B] - Crosshair ImplementedApr 15, 2025
- Devlog #03 - Implementing Shooting [Part-A] - Mechanices ImplementedApr 15, 2025
- Devlog #02 - Implementing Dash MechanicsMar 18, 2025
- Devlog #01 - New Input ManagerMar 13, 2025
Leave a comment
Log in with itch.io to leave a comment.