I create some game objects from a prefab and want to set individual colors per player.
The debug statement is executed, but I can’t see that the color is changing.
void setColor( GameObject go, VRPlayer vrp ) {
Renderer rend = go.GetComponent<Renderer>();
Shader shader = Shader.Find("Diffuse");
Material[] mat = rend.materials;
for ( int i = 0 ; i < mat.Length ; i++ ) {
if ( mat*.name.StartsWith("PlatformYellow")) {*
_ mat = new Material( shader );_
_ mat*.color = vrp.col;
Debug.Log(“found and assigned color=” + vrp.col );
break;
}
}
}
I also tried to reuse the shader (Line 8, in case I failed to setup the shader correctly)_
mat _= new Material( mat.shader );*
According to the [documentation][1] something like this should work:_
mat*.SetColor("Color", vrp.col );*
Would it be possible to get some upvotes so that I reach the 15 rep limit, it takes many hours until my questions have been reviewed. Thanks!
*[1]: http://docs.unity3d.com/ScriptReference/Material.SetColor.html*_