• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MOJAJA · Nov 12, 2019 at 04:16 AM · photonscorerpcpunsynchronize

Photon PUN2, Rpc score can't correctly.

Hi all , I have two ways now. But they can't send correct. I'm very confuse.

I want MasterClient send score to the other client ,and the other client send score to MasterClient.

Way1: It looks have no wrong, but it can't work

     [PunRPC]
     void MasterCount()
     {
             masterCount = gameCon.playerScore;
     }
 
     [PunRPC]
     void OtherCount()
     {
             otherCount = gameCon.playerScore;
     }
 
     void Update()
     {
        
         if(PhotonNetwork.IsMasterClient)
         {
             if (gameObject.GetComponent<PhotonView>().IsMine)
             {
                 if (gameCon.isClickButton)
                 {
                     masterCount = gameCon.playerScore;
                     scoreText.text = Mathf.Floor(masterCount).ToString("0");
                     gameObject.GetComponent<PhotonView>().RPC("MasterCount", RpcTarget.Others);
                 }
             }
         }
         else
         {
             if (gameObject.GetComponent<PhotonView>().IsMine)
             {
                 if (gameCon.isClickButton)
                 {
                     otherCount = gameCon.playerScore;
                     scoreText.text = Mathf.Floor(otherCount).ToString("0");
                     gameObject.GetComponent<PhotonView>().RPC("OtherCount", RpcTarget.Others);
                     
                 }
             }
         }
     }

Way2: I change the RPC , it looks very weird . The other can send othercount to Master , and Master still can't send .

 [PunRPC]
      void MasterCount()
      {
              masterCount = gameCon.playerScore;
      }
  
      [PunRPC]
      void OtherCount()
      {
              otherCount = gameCon.playerScore;
      }
  
      void Update()
      {
         
          if(PhotonNetwork.IsMasterClient)
          {
              if (gameObject.GetComponent<PhotonView>().IsMine)
              {
                  if (gameCon.isClickButton)
                  {
                      masterCount = gameCon.playerScore;
                      scoreText.text = Mathf.Floor(masterCount).ToString("0");
                      gameObject.GetComponent<PhotonView>().RPC("OtherCount", RpcTarget.Others);
                  }
              }
          }
          else
          {
              if (gameObject.GetComponent<PhotonView>().IsMine)
              {
                  if (gameCon.isClickButton)
                  {
                      otherCount = gameCon.playerScore;
                      scoreText.text = Mathf.Floor(otherCount).ToString("0");
                      gameObject.GetComponent<PhotonView>().RPC("MasterCount", RpcTarget.Others);
                     
                  }
              }
          }
      }

 


I don't know where is the problem , help me ,thank you !

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Captain_Pineapple · Nov 12, 2019 at 08:56 AM

Hey there,

you really have to learn to understand the documentation of photon... This is a really basic mistake you do there...


A RPC like any other function needs arguments you actually pass. Your current functions never transfer any data.

Let me put it like this: you have this function:

   [PunRPC]
   void OtherCount()
   {
           otherCount = gameCon.playerScore;
   }

then when you call

  photonView.RPC("OtherCount", RPCTarget.Others);

at player A; then there will only be a message outgoing from player A to call this function at all other players. Which means that player B will call OtherCount with values that are set in his own instance.


To actually send Data you need arguments:

   [PunRPC]
   void OtherCount(int count)
   {
          //do something with the value "count" here
   }

where you then can call

 photonView.RPC("OtherCount", RPCTarget.Others, valueYouWantToTransferToOtherPlayers);



Please read the documentation!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MOJAJA · Nov 12, 2019 at 09:40 AM 0
Share

As like you say , after I post the question , I found the problem. I really read the documentation of photon many times , because my bad English ,so there have something I can't understand. In my country, the information of photon , is not to clear .

Thank you for your reply :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

125 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Photon Unity Networking carrying scene objects 1 Answer

I'm trying to generate a random key and share it with other players when they join the game i'm using PUN. it's not working please help! 0 Answers

Photon PUN 2 RPC function doesn't change a variable value 2 Answers

Photon RPC relationship question. 0 Answers

How to check distance between two players (photon multiplayer) 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges