changing color of a prefab

Hi.

I’m making a 6player online game. I have a prefab as a player. When a player connects a copy of this prefab is created. I want each player have a different color. I have a color array. I use this code playerPrefab.renderer.material.color = PlayerColor[++i]; But this changes all the copies of prefabs. How can I change each players color independently?

Thanks for your help advanced

When you change the color of the prefab you are changing the sharedMaterial and it is applied to the other instances. You should change the color of the intance instead, not the prefab. Eg:

var go : GameObject = Instantiate(playerPrefab);
go.renderer.material.color = PlayerColor[++i]