I applied PlayerInfo script and when I join room to test, there are some players with same colors. how can I fix it? There are 7 colors in my all player colors.
here is my player's color script
using UnityEngine;
using Photon.Pun;
using System.Collections.Generic;
using UnityEngine.Experimental.Rendering.Universal;
using UnityEngine.UI;
public class PlayerInfo : Photon.Pun.MonoBehaviourPun, IPunObservable
{
public int colorIndex;
public SpriteRenderer[] playerBody;
public List<Color> _allPlayerColors = new List<Color>();
// public Text _playerName;
public Color CurrentColor
{
get { return _allPlayerColors[colorIndex]; }
}
private void Awake()
{
if (photonView.IsMine)
{
colorIndex = Random.Range(0, _allPlayerColors.Count-1);
// _playerName.text = PhotonNetwork.LocalPlayer.NickName;
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
// Owner.
stream.SendNext(colorIndex);
}
else
{
// Remote.
colorIndex = (int)stream.ReceiveNext();
}
}
private void Update()
{
foreach (SpriteRenderer playerPart in playerBody)
{
playerPart.color = _allPlayerColors[colorIndex];
}
}