RPC and Stream problem

Options
Im having troubles using RPC and onPhotonSerializeView the game im trying to make is a soccer game and when one players for example from the red team scores against the blue team the red team score would increase by one the issue is when player A from the red team scores two goals and then Player B just joined the server it is not synced across the network and the score would be 0-0 still is there a way to so that when the player join a server its score would still be synced across the network and it would be 2-0 to the red team in that case

void OnPhotonSerializeView(PhotonStream stream,PhotonMessageInfo info)
	{
		ball = GameObject.Find("Ball");
		if (stream.isWriting)
		{

		    stream.SendNext (blueScore);
			stream.SendNext (redScore);
			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
			stream.SendNext(ball.transform.position);
			stream.SendNext(ball.transform.rotation);

		}
		else
		{
			blueScore = (int)stream.ReceiveNext ();
			redScore = (int)stream.ReceiveNext ();
			position = (Vector3)stream.ReceiveNext();
			rotation = (Quaternion)stream.ReceiveNext ();
			ballposition = (Vector3)stream.ReceiveNext ();
			ballrotation = (Quaternion)stream.ReceiveNext();
		}

	}

	[RPC]
	public void scoreGoal(bool isBlue)
	{
		manager = GameObject.Find("PhotonManager").GetComponent<PhotonManager>();
		Debug.Log("RPC scoregoal been called");
		ball = GameObject.Find("Ball");
		redScoreText = GameObject.Find("Canvas/RedText").GetComponent<Text>();
		blueScoreText = GameObject.Find("Canvas/BlueText").GetComponent<Text>();
		if (isBlue)
		{
			blueScore++;
			blueScoreText.text = "Blue Score: " + blueScore;
			Debug.Log("BlueScores");
		}
		if (!isBlue)
		{
			redScore++;
			redScoreText.text = "Red Score: " + redScore;
			Debug.Log("Redscores");
		}

		if (rePosition != null)
		{
			rePosition(gameObject,ball);
		}
		if (rePosition != null)
		{
			rePosition(gameObject,ball);

		}


	}

Comments

  • vadim
    Options
    Looks like you use 2 different sync techniques at the same time for single value.
    For values shared by all players and not changed frequently, 3rd method preferred - room custom properties. Set them on any client any time and get on all others instantly.

    Note: PUN package contains PunPlayerScores.cs and PunTeams.cs helper scripts (they use room properties and player's as well). Even if this is not what you need exactly, you still may find some hints there.