• 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 /
  • Help Room /
avatar image
0
Question by Sylvine · Sep 16, 2015 at 08:48 PM · coroutineforeachtextfield

Strange behavior with if statement inside foreach

I want to have a score board (for now it's only showing pings but whatever) that player can look when they want. Here's my initial code :

 IEnumerator MAJTableauScore () 
     {
         while(Input.GetButton("Score"))
         {
             playerlist.text = "";
             foreach(PhotonPlayer playR in PhotonNetwork.playerList){
                 playerlist.text += playR.name + "  : " + playR.customProperties["Ping"]  + joueur.customProperties["Team"] + "\n";
             }
             yield return new WaitForSeconds(4f);
         }
     }

It's working fine, it shows the correct team for each player.

Now I want to add have my list like this :

 Team 1:
 *list of the players in team 1*
 
 Team 2
 *list of the players in team 2*

So I do this :

 while(Input.GetButton("Score"))
         {
             photonView.RPC ("updatePing", PhotonTargets.AllViaServer);
             playerlist.text = "";
             playerlist.text += "Team 1" + "\n";
             foreach(PhotonPlayer playRin PhotonNetwork.playerList){
                 if (playR.customProperties["Team"] == "team1") playerlist.text += playR.name + "    : " + playR.customProperties["Ping"] + "\n";
             }
             playerlist.text += "\n" + "Team 2" + "\n";
             foreach(PhotonPlayer playRin PhotonNetwork.playerList){
                 if (playR.customProperties["Team"] == "team2") playerlist.text += playR.name + "    : " + playR.customProperties["Ping"] + "\n";}
             yield return new WaitForSeconds(4f);
         }

Now it doesn't work anymore, it only shows the player running the code.

Comment
Add comment · Show 2
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 Dave-Carlile · Sep 16, 2015 at 08:59 PM 0
Share

I would guess that your customProperties["Equipe"] doesn't contain the values $$anonymous$$m1 or $$anonymous$$m2. Why does your first example use customProperties["Team"]?

avatar image Sylvine Dave-Carlile · Sep 16, 2015 at 09:18 PM 0
Share

Woops, little mistake, I translated the var names from French to English when copying it here so it's more clear. I'm going to change it. But no, the problem is not coming from here, on the first example it's working fine, the "playR.customProperties["Team"]" is changed to "$$anonymous$$m1" or "$$anonymous$$m2".

If you tell me the code should be working, then I guess it's another strange thing related to photon, but I hope not.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Sylvine · Sep 17, 2015 at 01:43 PM

Ok, I've got my answer. The code was fine, the problem was related to photon.

More info here : http://answers.unity3d.com/questions/1067246/rpc-target-mismatch.html#answer-form

Comment
Add comment · 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

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

29 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

Related Questions

What to do for many comparison operations in foreach loop? 0 Answers

Foreach in coroutine (Really need a reply!) 1 Answer

ui.text not seem in android game 1 Answer

Coroutine not waiting for yield WaitForSeconds [JS] 1 Answer

Local bool won't change inside coroutine 1 Answer

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