void ChangeMaterial(ModifyMaterialTrigger materialTrigger) { var shader = materialTrigger.Renderer.material.shader; var newMat = new Material(shader); newMat.CopyPropertiesFromMaterial(materialTrigger.Renderer.material); if (materialTrigger.NewAlbedo != null) { newMat.mainTexture = materialTrigger.NewAlbedo; } if (materialTrigger.NewNormal != null) { newMat.EnableKeyword("_NORMALMAP"); newMat.SetTexture("_BumpMap", materialTrigger.NewNormal); } if (materialTrigger.NewMetallic != null) { newMat.EnableKeyword("_METALLICGLOSSMAP"); newMat.SetTexture("_MetallicGlossMap", materialTrigger.NewMetallic); } //newMat.EnableKeyword("_EMISSION"); //newMat.SetColor("_EmissionColor", materialTrigger.EmissionColor); newMat.color = materialTrigger.AlbedoColor; materialTrigger.Renderer.material = newMat; }
IEnumerator ChangeMaterialAfterDelay(ModifyMaterialTrigger materialTrigger) { yield return(new WaitForSeconds(materialTrigger.Delay)); ChangeMaterial(materialTrigger); }