Good people!
It’s my first post and I’ve been going crazy for like two days.
I have managed without problems to be able to spawn the players with different colors by means of the code
materials [Random.Range (0, materials.Length)]
So far so good because each player assigns them to me a material and they can be repeated but my idea is up to a maximum of 3 players with each color (as if they were 3 teams).
I am blocked and I need your help.
I have tried various for, while, if, etc with no positive results.
GameObject playerInstantiate;
public GameObject[] spawnPoints;
public Material[] materials;
spawnPoints = GameObject.FindGameObjectsWithTag ("Spawn");
for (int i = 0; i <spawnPoints.Length; i ++)
{
int colorNum = Random.Range (0, 3);
playerInstantiate = Instantiate (player, spawnPoints _.transform.position, spawnPoints *.transform.rotation);*_
playerInstantiate.transform.SetParent (spawnPoints .transform);
playerInstantiate.GetComponent () .material = materials [Random.Range (0, materials.Length)];
}
The problem comes that I don’t know how to solve in the loop if there are already 3 players with the same color and pass or assign the next color.
I hope it has been understood and I think the code I want to do is not very difficult but I am blocked and I do not want to do it manually in case in the future I can expand the number of players.
By the way I have found similar themes but I have not been able to adapt them to the expected result. If the post already exists please apologize.
Regards, and thank you very much