RPC Functions with Photon PUN 2 in Unity (Part 8)



How to make a Multiplayer Video Game

Discord:

For this lesson on how to make a multiplayer video game in Unity with the Photon 2 plugin in Unity 3D, I will show you how to create a character selection option that will then synchronize the selected character across the network. Features like the are prevalent in many video games today such as Rainbow Six Siege, Call of Duty Black Ops 4, and Fortnite. This lesson will teach you the basics of RPC or Remote Procedure Call Functions. RPC’s are probably one of the most important principles in developing a multiplayer video game. It is through RPC functions that we are able to sync data from one client to another. After following this tutorial you should be able to create your own RPC function and implement them into your own video games.

SUBSCRIBE for regular Video Game making videos:

In between lesson I create a menu system with four different buttons. This will allow us to selected different characters for us to use as your player avatar prefab. We will begin by creating a new C sharp script called Player Info. This script will save the value of the character our player has chosen.

We then need to create a new C# script that will control do a new menu system. Inside this function, we only need to have a public function that will set the value of the character model we want to use.

We then need to create a Player Info object and a Menu Controller Object. We will then set the on click events of your buttons in our menu system.

We then need to create another C# script. Inside this script, we will create an RPC function that will synchronize our character model value across the network and instantiate it.

If you followed along with the video you should now be able to build your project. Once built you should be able to select different character model which will then be instantiated into the multiplayer scene once connected.

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

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

26 Comments

  • Chance Slaughter32

    It hurts me to see you look at the keyboard while typing lol… Great video and very helpful!

    June 21, 2020 - 2:14 am Reply
  • shoaib malik

    i made a scene in which i build a robot with different weapons but it got it own cavas and camera all these are the childs so how do i show the host's view to himself
    my hirarchy is almost like that for a robot main
    ->robot main
    | ->robot
    | | -> robot got scrips to move rotate
    | | | -> camera
    | | -> weapons
    | ->canvas
    | | -> ammo bar
    | | -> health bar
    | | -> player name

    June 21, 2020 - 2:14 am Reply
  • Janus C

    Thanks man

    June 21, 2020 - 2:14 am Reply
  • Ochlan Gaming

    good tutorial

    June 21, 2020 - 2:14 am Reply
  • Aashu Ram

    My question is that how can I control my 4 character animation …I got so many problems …plz reply

    June 21, 2020 - 2:14 am Reply
  • LIRDCE

    Hello!

    I watch your photon pun 2 tutorial series and want to use as an base for my multpilayer game because this is my first game.

    I get an trouble in the 8. video.

    I remake all the project twice and cant get rid of this problem

    If i run the build and the build and choose character when i get in to the MP-scene in the editor the character is disappear and not controllable and in the build version is not disappear but also not controllable.

    Can you help me troubleshoot this 2 error in my project?

    June 21, 2020 - 2:14 am Reply
  • I I

    Can you replicate and do tutorials from real life examples as Escape from Tarkov game mechanics in Unity's Photon PUN 2??? That game (as far I know) are made with Unity.

    June 21, 2020 - 2:14 am Reply
  • rivenblades

    In this series, i didn't understand which is the server and the client? When i want to export my game and give the exe to client, what is the program I keep for the server??

    June 21, 2020 - 2:14 am Reply
  • Jhin Shots

    2020 Still the best photon tutorial ♥

    June 21, 2020 - 2:14 am Reply
  • Whoa Apps

    Dude. You're awesome. Thank you for making these videos.

    June 21, 2020 - 2:14 am Reply
  • Manish Otaval

    How to call RPC from other script?

    June 21, 2020 - 2:14 am Reply
  • M Saradi

    Thanks for the tutorial sir.but I need to instatiate different 3d models for different users.iam stuck with this.i created user login but able to instatiate only 2 different models for two users.please help me sir

    June 21, 2020 - 2:14 am Reply
  • Manish Otaval

    PlayerAvatar instantiate character graphics and make it child transform. How to replace character with PlayerAvatar?

    June 21, 2020 - 2:14 am Reply
  • daniel fayemi

    Pls Do Turn Based PUN

    June 21, 2020 - 2:14 am Reply
  • Elnur Ceferli

    Did you move characters with PlayerMovement script which you wrote it #7.Video?

    June 21, 2020 - 2:14 am Reply
  • 1amKing

    Thax.

    June 21, 2020 - 2:14 am Reply
  • WiTech

    hey guys, so i need help really fast bc, i'm making a game jam w/ my school friends and i have a little problem, when i have 2 avatars in a room, the movement of 1 is synced w/ the 2 players, but what is synced and displayed on the other instance of the game is just the 1's movement, i dunno if i'm clear but i need help thx guys

    June 21, 2020 - 2:14 am Reply
  • Jérémie

    Thank you !

    June 21, 2020 - 2:14 am Reply
  • faraz khan

    the Movment is not smoth of player how we can create smooth movement. i have a 2d charachter he is free falling charchter and when i tap it move in y direction but movment is not smoth how can i make the movment smooth.?

    June 21, 2020 - 2:14 am Reply
  • Omris 1998

    I'have a problem about RpcTarget , RpcTarget name does not exist in current context

    Can you help me pls

    June 21, 2020 - 2:14 am Reply
  • Omris 1998

    Really thank you so much i was looking for this since two days , finally found on your channel pls keep it up!

    June 21, 2020 - 2:14 am Reply
  • FoestarEnt.

    Maybe someone in here can help with an issue I'm having that literally no one has been able to answer yet and I've failed to fix. When updating a string across the network through an RPC, lets say a string called "firstPlace", we send the RPC out like so: base.photonView.RPC("FirstSent", RpcTarget.All, nameToBeSent);

    nameToBeSent is another string we use with the persons named stored in it. FirstSent is the name of the RPC. Then we do the RPC like so:
    [PunRPC]

    public void FirstSent(string nameToBeSent)

    {

    firstPlace = nameToBeSent;

    FirstPlace.GetComponent<Text>().text = "1st: " + nameToBeSent;

    }
    This takes in nameToBeSent and then tries to make firstPlace equal that string. It then makes a text field say 1st and that players name. The second part works with showing the name for every player. But the updating the firstPlace spot does not for every player. They all see the correct name but do not store it in their firstPlace strings. Why is that?

    June 21, 2020 - 2:14 am Reply
  • bi jian Wu

    any one can tell me what is deference between
    private void OnEnable()

    {

    if(Instance == null)

    {

    Instance = this;

    }

    else

    {

    Destroy(gameObject);

    }

    }
    and this one:
    private void OnEnable()

    {

    if(Instance == null)

    {

    Instance = this;

    }

    else

    {

    if(Instance != this)

    {

    Destroy(Instance.gameObject);

    Instance = this;

    }

    }

    }

    I think they do the same thing, isn't it? or am i wrong?

    June 21, 2020 - 2:14 am Reply
  • Ömer Faruk Sarıışık

    But is it safe to keep this data in client ? I thought my game could have been hacked. Shouldn't we keep this data on Server side ?

    June 21, 2020 - 2:14 am Reply
  • Kidopya

    Hello first of all thank you for awsome tutorials:)I have a question: In your AvatarSetup script, in the RPC_AddCharacter function, why did you use Instantiate; instead of PhotonNetwork.Instantiate?

    June 21, 2020 - 2:14 am Reply
  • Ian Hernandez

    Not sure why, but my character wont move. My PlayerAvatar does move (which you cant see in build since the mesh was disabled), but the model itself just spawns and doesnt move with the PlayerAvatar. It seems like when it spawns its not falling in under a child of PlayerAvatar. Any suggestions? Love the granularity in your tutorials by the way! Thanks!

    June 21, 2020 - 2:14 am Reply

Leave A Comment

Your email address will not be published.