Unity Photon Sync Points

Issue

This Content is from Stack Overflow. Question asked by JWalker

I am trying to sync the points so when a player collides with an object they get a point.
The problem is it does not update on the other players screen when that player gets a point. I’ve been trying to sort this code for a while but can’t figure it out how to make it work. Thanks

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Photon.Pun;

public class FlagPoints : MonoBehaviour
{
    public TextMeshProUGUI text;
    public TextMeshProUGUI text2;
    private GameObject Flag;
    PhotonView PV;

    public static int points = 1;
    private int CurrentScore = 1;

    public string tagToCompare = "Floor";

  
    void OnTriggerEnter(Collider col)
    {
        if (col.transform.tag == tagToCompare)
        {
            Debug.Log("It works!");
            if (PhotonNetwork.IsMasterClient)
            {

                
                if (PV.IsMine)
                {
                    PV.RPC("DisplayScore", RpcTarget.All, text);
                }
                Destroy(Flag);
                
            }
            else
            {

                
                if (PV.IsMine)
                {
                    PV.RPC("Display2ndScore", RpcTarget.All, text2);
                }
                Destroy(Flag);

            }
        }
    }

    [PunRPC]
    void DisplayScore(int CurrentScore)
    {
        text.SetText("points:" + CurrentScore++);
    }

    [PunRPC]
    void Display2ndScore(int CurrentScore)
    {
        text2.SetText("points:" + CurrentScore++);
    }



}



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?