Having errors when I added a function in the RPSCore.

Options
I added EnemyHP.value = EnemyHP.value - local.GetScore (); in the RPSCore code.
public void UpdatePlayerTexts()
    {
        PhotonPlayer remote = PhotonNetwork.player.GetNext();
        PhotonPlayer local = PhotonNetwork.player;

        if (remote != null)
        {
            // should be this format: "name        00"
            this.RemotePlayerText.text = remote.name + "        " + remote.GetScore().ToString("D2");
			EnemyHP.value = EnemyHP.value - local.GetScore ();
        }
        else
        {

			TimerFillImage.anchorMax = new Vector2(0f,1f);
			this.TimeText.text = "";
            this.RemotePlayerText.text = "waiting for another player        00";
        }
        
        if (local != null)
        {
            // should be this format: "YOU   00"
            this.LocalPlayerText.text = "YOU   " + local.GetScore().ToString("D2");
			PlayerHP.value = PlayerHP.value - remote.GetScore ();
        }
    }

and now im currently having these errors..
NullReferenceException: Object reference not set to an instance of an object
ScoreExtensions.GetScore (.PhotonPlayer player) (at Assets/Photon Unity Networking/UtilityScripts/PunPlayerScores.cs:35)
RpsCore.UpdatePlayerTexts () (at Assets/Photon Unity Networking/Demos/DemoRockPaperScissors/Scripts/RpsCore.cs:429)
RpsCore.Update () (at Assets/Photon Unity Networking/Demos/DemoRockPaperScissors/Scripts/RpsCore.cs:182)



can someone help me please.. Thanks

Comments

  • jeanfabre
    Options
    Hi,

    Your photonPlayer pointer is null. So before you call GetScore, check that it's not null, else, put a log. It's likely your remote player that is null.

    Bye,

    Jean
  • o0Holic0o
    Options
    So that just means that there are no other players connected in the lobby with me?
  • jeanfabre
    Options
    You should check with PhotonNetwork.countOfPlayers and PhotonNetwork.countOfPlayersInRoom for this.

    Bye,

    Jean