Rise - need help for a character selection system

Hello guys, I am currently creating a game for a children hospital for kids with asthma and cystic fibrosis and in the game (online) the players has to select a character, but when that character is selected, all players in the lobby has to see that one of the player has selected one of the 4 possible avatar and can't take this one anymore unless that player decides to change its selection. I tried many different variations but none worked so far. I have this one for the time being:

using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;

public class CharacterSelectionController : MonoBehaviour
{
private PhotonView PV;
public Button[] buttons;

private int[] nb = { -1, -1, -1, -1 };

void Start()
{
PV = GetComponent<PhotonView>();
}

[PunRPC]
public void a(int characterIdentifier)
{
PV.RPC("SelectCharacter", RpcTarget.AllBufferedViaServer, characterIdentifier);
Debug.Log("1");
}

[PunRPC]
public void OnClickCharacterPick(int characterIdentifier)
{
if (PlayerInfo.playerInfo != null)
{
Debug.Log("2");

PlayerInfo.playerInfo.mySelectedCharacter = characterIdentifier;

for (int i = 0; i < nb.Length; i++)
{
buttons[characterIdentifier].interactable = false;
if (i == characterIdentifier)
{
continue;
}
else
{
buttons.interactable = true;
}
}
PlayerPrefs.SetInt("LOCALCHARACTER", characterIdentifier);
}
}
}


You have 4 buttons and when you click one it assigns a number through the OnClick method of the Button UI system. It works well offline but not online. Each can select his character and that one is deactivated once selected and reactivated if he choose another. The problem is that the other players can't see that, they can all take the same characters and that would cause a problem for the game... Can anyone help me solve this issue?
Sign In or Register to comment.