using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimateMaterialExposure : MonoBehaviour { public Renderer[] targetRenderers; public float newExposureWeight; Material[] materials; bool isAnimatingMaterial; private void Start() { materials = new Material[targetRenderers.Length]; for (int i = 0; i < targetRenderers.Length; i++) { materials[i] = new Material(targetRenderers[i].material); targetRenderers[i].material = materials[i]; } } public void AnimateMaterialUpdate() { for (int i = 0; i < targetRenderers.Length; i++) { //materials[i].SetFloat("_EmissiveExposureWeight", newExposureWeight); Color emissiveColor = materials[i].color; materials[i].SetColor("_EmissiveColor", new Vector4(0.8803151f, 0.5380651f, 0f, 1f) * newExposureWeight); targetRenderers[i].material = materials[i]; } } public void RunCoroutineToUpdateMaterial() { if (!isAnimatingMaterial) { StartCoroutine(UpdateMaterial()); } } public void StopCoroutineThatUpdatesMaterial() { isAnimatingMaterial = false; } IEnumerator UpdateMaterial() { isAnimatingMaterial = true; while (isAnimatingMaterial) { AnimateMaterialUpdate(); yield return null; } } }