- Home /
Question by
bburtson09 · Dec 16, 2016 at 01:45 PM ·
arraytexturessettingsmaterial renderer
Attempting to change SetTexture("_DetailAlbedoMap", randomTexture) In children?
Hey guys, I am using this method below to : Get an array of textures from another game object's script. then select a random texture from that array and assign it to this game objects material in children. I am not getting errors, and its returning a random texture, but no results.
// Called in start, attached to player game object.
void GetColors()
{
ColorInitializer colorInitializer = gcGo.GetComponent<ColorInitializer>();
GameObject helmGo = transform.GetChild(5).gameObject;
print(transform.GetChild(5).gameObject);
Renderer helmRend = helmGo.GetComponent<Renderer>();
Material helmText = helmRend.material;
int randomColor = Random.Range(0, colorInitializer.playerColors.Length);
Texture randomTexture = colorInitializer.playerColors[randomColor];
helmText.SetTexture("_DetailAlbedoMap", randomTexture);
}
Comment
I answered my own quiestion I used https://docs.unity3d.com/ScriptReference/$$anonymous$$aterialPropertyBlock.Clear.html