I’m still new to the networking part, but I decided to go with PUN since I read a lot of reviews that said it was easier to use and the fact they give you a free small server to use. Following the marco-polo tutorial a bit, I created a script that instantiates a “player” object that has some gui code on it that allows the player to setup their char and then choose to battle others that are in the room. This is a simplified version of the code, but it demonstrates the problem I’m running into.
void OnGUI()
{
if (photonView.isMine)
{
if (pageNumber == 0)
{
if (GUI.Button(new Rect(25, 25, 100, 20), "Next"))
{
pageNumber++;
}
}
if (pageNumber == 1)
{
if (GUI.Button(new Rect(25, 25, 100, 20), "Button to select opponent"))
{
playerPhotonView.RPC("ChallengePlayer", PhotonTargets.Others);
}
}
if (pageNumber == 2)
{
if (GUI.Button(new Rect(25, 25, 100, 20), "Decline challenge"))
{
pageNumber--;
}
}
}
}
To clarify,
pageNumber == 0 would be let you pick your char and setup
pageNumber == 1 would have a list of possible opponents based on those in the room and allow you to challenge them. In my normal code, a button is created for each person that you can challenge.
pageNumber == 2 means you have been challenged, and the gui will let you accept or decline, sending you to a room if accept and back to the challenge screen if decline.
[RPC]
void ChallengePlayer()
{
Debug.Log(pageNumber + " challenged page number");
//script will include information about challenger
if(pageNumber == 1)
pageNumber = 2;
}
The above is the RPC code, it checks if the player is on the challenge screen and thus ready to go before setting their gui to the challenge accept/decline screen.
The problem I’m running into is this. I can load up two chars (one separate and one in the unity editor). I can get them both to the screen that lets them challenge each other without any issues. But, when I have player one (solo screen) call the RPC in player two (unity editor) the debug.log shows pageNumber == 0 despite the fact that it is on the challenge screen and should be equal to 1.
I can also remove the if check and just have it set the pageNumber == 2. Clicking to challenge twice gives me
0 challenged page number
2 challenged page number
The OnGUI doesn’t change even after the second click.
The question is, is there something about how OnGUI works with RPCs?
Thanks for any help.