Good day,
i try to make a new multiplayergame with MLAPI i started this day so i ont have much experiecense btw. I passed all what i need but yet i dont pass the goal, i have a playerspawner-Script they are colored with one btw. the same Material(I spawn the Prefab). But rigth now i want to make a Color choser the Problem is when i change my Material all characters change i first tryed the Color chooser whith a video, in the Video the Person chnaged it with the renderer of the object / prefab (ColourRenderer.material.SetColor(“_BaseColor”, Colours[newColorIndex]) after i searched on the Web and in the Documentations usw. but i found nothing to this theme and so i am here. (I have images where i give the numbers this work perfectly i tested it whith a print method, and than i have a array of colors that i put in the PlayerColor script bzw. when i get index 1 color Array one is the Actual Color)
Thanks to advance to all!
Details
Unity version: 2021.1.17f1,
MLAPI version: 0.1.0
(The Color change code is down bellow)
//ColourPicker (Is in a emty object where all canvasess are in!)
using MLAPI;
using MLAPI.Connection;
using UnityEngine;
namespace FyMa2618.UMT.NetworkVariables
{
public class ColourPicker : MonoBehaviour
{
public void SelectColor(int colorIndex)
{
print(colorIndex);
ulong localClientId = NetworkManager.Singleton.LocalClientId;
if(!NetworkManager.Singleton.ConnectedClients.TryGetValue(localClientId, out NetworkClient networkClient))
{
return;
}
if(!networkClient.PlayerObject.TryGetComponent<PlayerColor>(out PlayerColor playerColor))
{
return;
}
playerColor.SetColorServerRpc((byte)colorIndex);
}
}
}
//PlayerColor(Is on the Player prefab)
using MLAPI;
using MLAPI.Messaging;
using MLAPI.NetworkVariable;
using UnityEngine;
namespace FyMa2618.UMT.NetworkVariables
{
public class PlayerColor : NetworkBehaviour
{
public Renderer ColourRenderer;
public Material player;
public Color[] Colours;
private NetworkVariableByte colorIndex = new NetworkVariableByte();
[ServerRpc]
public void SetColorServerRpc(byte newColorIndex)
{
if(newColorIndex > 3) { return; }
colorIndex.Value = newColorIndex;
}
private void OnEnable()
{
print("Enable");
colorIndex.OnValueChanged += OnColorChanged;
}
private void OnDisable()
{
print("Disbale");
colorIndex.OnValueChanged -= OnColorChanged;
}
private void OnColorChanged(byte oldColorIndex, byte newColorIndex)
{
if(!IsClient) { return; }
print("Suces");
//ColourRenderer.material.SetColor("_BaseColor", Colours[newColorIndex]);
player.color = Colours[newColorIndex];
print("AASuces");
}
}
}