When entering the server, the player calls the RPC function that increases the number of players, it works correctly. Another RPC function is responsible for the player's death, but it changes the variable only for one client, the value does not change for the rest.
the script in which the function does not work
using Photon.Pun;
using UnityEngine;
public class PigLifeScript : MonoBehaviour
{
PhotonView view;
private void Start()
{
view = GetComponent<PhotonView>();
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "WolfPlayer")
{
view.RPC("RemovePlayer", RpcTarget.AllViaServer);
}
}
}
Functions
private int AlivePigs;
public Text AlivePigsTXT;
[PunRPC]
public void AddPlayer()
{
AlivePigs++;
}
[PunRPC]
public void RemovePlayer()
{
AlivePigs--;
}
I tried to call RPC from a separate function, tried to make conditions in the Update method, tried to pass the value to the master client,