Im using an asset I bought some time ago, and using some models from it. This is the model:
My question is, how could I dynamically change things like the hair, the uniform, etc? The asset comes with various PNG files for every part of the model (face, hair, shoes, etc.) and I would like the player to be able to shoose a hair, a skin, etc. for the model. I see a list of materials slots in the Inspector where they are set, but don't know how to do it programatically.
EDIT:
I (sort of) achieved what I wanted, this way:
if(Input.GetKeyDown(KeyCode.T)){
GameObject polyMesh = selectedUnit.transform.Find("Polymesh").gameObject;
GameObject model=polyMesh.transform.Find("model_001").gameObject;
SkinnedMeshRenderer mesh=model.GetComponent<SkinnedMeshRenderer>();
Material[] materials = mesh.GetComponent<Renderer>().materials;
Material WhiteUniform = Resources.Load<Material>("Materials/WhiteShirt");
materials[1] = WhiteUniform;
mesh.GetComponent<Renderer>().materials=materials;
}
Now my problem is that it changes the shirt of all the players. It is possible to change the material of only the selected player?
