// Here you pass in your skinnedMeshRenderers and can change // the material's color on them. Pass in the default color to go back to // it when vulnerable again. public static void MaterialColorChange(this SkinnedMeshRenderer[] mySkinnedMeshes, ColorChangeTypes colorChange, Color myDefaultColor, bool vulnerable = true) { Color newColor = myDefaultColor; if(colorChange == ColorChangeTypes.Is_Vulnerable) { if(!vulnerable) newColor = Color.cyan; // Color I use for invulnerability. } else if(colorChange == ColorChangeTypes.Healed) newColor = Color.green; // Heal color. foreach(SkinnedMeshRenderer myMesh in mySkinnedMeshes) { foreach(Material mat in myMesh.materials) mat.color = newColor; // Assign this color to each material. } }
// Setup for changing color. I make the character change to a light blue // when they aren't vulnerable to show that. public void StartMaterialColorChange(float timeToChangeFor, ColorChangeTypes colorType) { // When this timer reaches 0, we will go back to our normal color // and be vulnerable again. _matOrFlashChangeTimer = timeToChangeFor; _matOrFlashChange = true; _myFlashType = FlashType.Color_Change; // Check MyExtensionMethods to see this method. mySkinnedMeshes.MaterialColorChange (colorType, _myDefaultColor, colorType == ColorChangeTypes.Is_Vulnerable && Vulnerable); }