Can not get my coloring of players with different colors to work [Solved]

Options
Jinba
Jinba
Hi
I'm working on a arena fighter game. I'm very new to PUN. Right now i have a "waitingRoom" where up to 4 players are waiting for the game to start. Then a player joins a room he need to get on of the following colors: Red, Blue, Green, Yellow. The color depends on which color that isn't taken by another player. Right now i use PhotonNetwork.Instantiate, to create a player prefab then OnJoinedRoom(); is called. The "Player" prefab has a script i use to color the color. It works fine until a specific player leaves the room.

So let's say the first player who joins the room gets the color Red, and the 2.player gets the color Blue, and the 3. player gets the color green. If the 3. player leaves the room and rejoins, every thing work just fine. but then the 2. player leaves and rejoins every is fine on the other clients screen. But on the 2. players screen he got the green color.

My methods look like this:




//Called by void Start()
private void setColor()
{
if (PhotonNetwork.isMasterClient)
{
photonView.RPC("rpcColor", PhotonTargets.AllBuffered);
}
}




[PunRPC]
private void rpcColor()
{
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
bool[] colorsTaken = new bool[4];

foreach (var player in players)
{
if (player.transform.FindChild("Red(Clone)"))
{
colorsTaken[0] = true;
}

if (player.transform.FindChild("Blue(Clone)"))
{
colorsTaken[1] = true;
}

if (player.transform.FindChild("Green(Clone)"))
{
colorsTaken[2] = true;
}

if (player.transform.FindChild("Yellow(Clone)"))
{
colorsTaken[3] = true;
}
}

for (int i = 0; i < colorsTaken.Length; i++)
{
if (!colorsTaken[i])
{
Instantiate(teamColor[i], gameObject.transform, false);
return;
}
}
}

Thanks in advance :)

Best Answer

Answers

  • Tobias
    Options
    There is also a component called "ColorPerPlayer" or similar. You could base your colors on that maybe?
  • Jinba
    Jinba
    edited January 2017
    Options
    Tobias said:

    There is also a component called "ColorPerPlayer" or similar. You could base your colors on that maybe?


    That might be an option too. I will look into it, later on. For now i'm just sticking with the solution i made. But much thanks for your reply Tobias.