Adding and getting Players score in team.

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Adding and getting Players score in team.

saad
2023-01-13 15:05:56

Hi! I'm very new in photon. Right know I'm making a score system on network

I have a goal game scenario when a player 1 make a goal to player 2 I add a score to player 1 who make a goal and same with second player, its working fine both players can see each others score on screen,

But the issue is when I play 2 VS 2 and if the one player make a goal the all players got a score

and some time, some players got a score , In 2 Vs 2 score system is not working proper,

I have script on player goal net when a Ball hit using this way i add score;

if (other.gameObject.tag=="BIGBALL")    
{    
    allPlayers = FindObjectsOfType<PlayerMover>().ToList();    
    for (int i = 0; i < allPlayers.Count; i++)    
    {    
        if (allPlayers[i].PV.IsMine)//&& !addscore )    
        {    
            if (id != allPlayers[i].playerID)    
            {    
                allPlayers[i].PV.Owner.AddScore(1);    
                    //addscore = true;    
            }    
        }    
    }    

And in GameManager script I make a function and call it in each player script using

InvokeRepeating the function is:

public void updateScore()    
{    
   int TeamOneScore=0;    
   int TeamTwoScore=0;    
       
   for (int i = 0; i < PhotonNetwork.PlayerList.Length; i++)    
   {     
       //if(PhotonNetwork.PlayerList[i].CustomProperties["Team"]== PhotonNetwork.LocalPlayer.CustomProperties["Team"])    
       if(PhotonNetwork.PlayerList[i].CustomProperties["PlayerID"]== PhotonNetwork.LocalPlayer.CustomProperties["PlayerID"])    
       {    
            TeamOneScore+=PhotonNetwork.PlayerList[i].GetScore();    
       }    
       else     
       {    
            TeamTwoScore += PhotonNetwork.PlayerList[i].GetScore();    
       }    
           
   }    
   text0.text = TeamOneScore.ToString();    
   text1.text = TeamTwoScore.ToString();    
}    

anyone who help me.

Comments

Back to top