// Temp. private void Setup() { _elementManager = FindObjectOfType <ElementManager>(); _as = GetComponent <AudioSource>(); _colourMaster = new ColourMaster(); _startColours = _colourMaster.GetColours(_renderersToFade); }
private IEnumerator Fade(Renderer[] renderers, float targetAlpha, float duration) { Color[] startColours = _colourMaster.GetColours(_renderersToFade); var step = 0.0f; while (step < 1) { step += Time.deltaTime / duration; for (int index = 0; index < startColours.Length; index++) { Material mat = renderers[index].material; Color startColour = startColours[index]; Color targetColour = _colourMaster.ChangeAlpha(mat.color, targetAlpha); mat.color = Color.Lerp(startColour, targetColour, step); renderers[index].material = mat; } for (int index = 0; index < _particlesSystemsToFade.Length; index++) { Color startColour = _particlesSystemsToFade[index].main.startColor.color; Color targetColour = _colourMaster.ChangeAlpha(startColour, targetAlpha); ParticleSystem.ColorOverLifetimeModule colourModule = _particlesSystemsToFade[index].colorOverLifetime; colourModule.color = Color.Lerp(startColour, targetColour, step); } yield return(null); } yield return(null); }