RPC in FPS with Photon PUN 2 in Unity (Part 10)


How to make a Multiplayer Video Game


For this tutorial lesson, on how to make a multiplayer game in Unity using the Photon 2 plugin we will be using the RPC functions we have learned about to make a basic first-person shooter control that will sync across the network. This tutorial will teach you how to use the RPC function of the Photon 2 plugin in other scenarios. After this lesson, you should have a better understanding of RPC function and what they can do as well when to use them. You will also learn how to take any game machinic and make it work in a multiplayer game.

SUBSCRIBE for regular Video Game making videos:

We will begin by creating variables in our Avatar setup script for the first one will be player health and the next one will be player damage. We will then create a new C# script called Avatar Combat. In this script, we will create some new variables. We will then initialize these variables. We will then create a shooting function and we will use Raycast to do this. We first want to check for player input and then we will create our Raycast. If the Raycast hit another player then we want to remove health from that player. We will then save our C# script and go back to Unity.

In Unity, we will create and add a new camera to our player avatar object. We then need to attach our new scripts to their respective object and set the variables.

We will then go back to our Avatar combat script and we will turn this script into a script that will work across the network. We will do this by creating an RPC function that will synchronize the player’s health across the network when the player has been shot.

If you followed along with the video then you should now have a working basic FPS controller that networks the player’s health when shot.

Nguồn: https://uwallpaperhd.com/

Xem thêm bài viết khác: https://uwallpaperhd.com/game/


  1. Thanks for the tutorial took me a while to get and I get really annoyed when it keeps on saying things like "Object not set to an instance of an object" and stuff like that. Cheers

  2. Could be nice to see mobile touch input for Multiplayer game as well. You are the best what I have seen for Unity Multiplayer explanation.!!!

  3. @Info gamer – can you do simple characters inventory replication and weapon PICK -up and DROP-down scripts for Photon PUN 2? Could be nice to see another scripts like player Death and player random respawn in maps random spawn points.

  4. Hi. I want to spawn origin objects for one match. For example: When i created a match and spawned 20 objects, so all players in match see the same 20 objects. How can i do that? Thank a lot.

  5. Hi, great tutorials! I'm having an issue where my character's Character controller is never grounded on the terrain (isGrounded is never true). I'm going nuts with this. When I add a RigidBody to it it flies up in the air when I rotate him???? Do you know how to fix this?

  6. This particular video just seals the deal for me. The way you emphasize on concept explanation rather than just writing code and creating a game just makes the whole series amazing.

  7. (When we spawn in multiplayer scean) Is it possible that we first check if player is mine and if yes then only add components like camera, controller, etc..?

  8. hi great tutorials I've managed to get a multiplayer room working in a way shorter amount of time than expected, however in i cannot get the client to change its health numbers, the damage is happening i can see it in the editor and the text is set to 100 on start, the editor main client changes when hit though,
    edit; Forgot to put on the Photontransform for my RayCastPoint, i've been making a third person game instead so had to have the ray shoot from in front of the player so i didn't hit myself , whoops,

  9. If I were to instantiate a bullet within RPC_shooting would it be using PhotonNetwork.instantiate or just instantiate?

  10. For some reason in my editor the health updates when I am shot from the standalone, but when I am shot from the editor the standalone's health doesn't update. In unity the local health for the standalone is updated and in the standalone the health is set to 100 at start.

  11. Debug.DrawLine() has a time parameter. If you set it greater than 0, it will keep that line drawn for that many seconds.

  12. Thank you for these videos. I will say, you reorganize that desk to your right behind you a lot 😛 One video I see a bookcase on it, another without, then another with! haha

  13. Hello Everyone, I want to rotate the Avatar's 'rightarm' using 'T' button I want the same to be synchronized across the network. Could someone please help me out with that.

  14. Hey! great videos, they are a lot of help. I have one question about that RPC_Shooting method, is it really ok to tell every client cast rays for the same thing? Could there be an edge case where the rays hits in some clients but no in others? Does it solves those conflicts taking the masters results as truth?. Other way could be making the raycast locally and sending the results, but if the client shooting has lag he might be using old information to make the calculation and still cause a suboptimal online experience.

  15. Hello! If someone uses Cheatengine or some other programs, could they modify values ​​like playerHealth and playerDamage? What is the best way to store variable values ​​to avoid their external modification?

  16. You deserve way more likes and views for doing these tutorials, I'm so glad to get up to date PUN tutorials!

    Just as a note for people with recent versions of PUN, for some reason the "RpcTarget.All" function doesn't exist that he uses. I checked the autocorrect as I typed and it turns out there's a whole section called PhotonTargets.All and this seems to be the right piece of code but could somebody confirm? The description matches what he's talking about but I wanted to double check.

  17. Do you think calling the rpc in everyframe is a good way of shooting ? Because as long as I know, photon has a certain limit of calls per second such as 500 (I guess). So, I am thinking about calling rpc just at the very beginning and the very end of shooting sequence. This can be done with an OnMouseDown check with changing a boolean to true. That way all the clients will shoot locally and they only broadcast what they started and finished, we also see they are shooting besides we dont use a lot of rpc calls as well.

  18. Thank you very much for awesome guides! I just wanna say ".CompareTag(tag)" is more efficient than " == tag"

  19. Hi! Thanks for the great tutorials. How would you script the camera if it was a sideview multiplayer platform game ?(like this video, just in multiplayer: https://www.youtube.com/watch?v=MFQhpwc6cKE).

  20. Great! Thanks for this lesson.
    Sir I am trying to make a turn based game between two players using photon.
    Sir,Please arrange a lesson for a Turn Based Game using photon..There is very few information on turn based game in photon..

  21. Hey, Nice Tutorial thanks a lot! and yes i have a question too. When i build and play the game in 2 stand alone windows they both work fine but with a stand alone and editor they both create their own rooms instead of joining the existing one?


Please enter your comment!
Please enter your name here