Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

I need help for player's color index isue

A topic by silvakim created Dec 01, 2021 Views: 163
Viewing posts 1 to 2

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];
}


}

Moderator moved this topic to General Development