// Update is called once per frame void Update() { if (brokenness != lastFrameBrokenness) { if (brokenness == 0.0f) { thruster.OnBrokenChange(broken: false); } if (brokenness == 1.0f) { thruster.OnBrokenChange(broken: true); } lastFrameBrokenness = brokenness; float startIntensity = repaired.r + repaired.g + repaired.b; float goalIntensity = broken.r + broken.g + broken.b; float currentIntensity = Mathf.Lerp(startIntensity, goalIntensity, brokenness); var lerpedColor = Color.Lerp(repaired, broken, brokenness); float intensityLerped = lerpedColor.r + lerpedColor.g + lerpedColor.b; material.color = lerpedColor * (currentIntensity / intensityLerped); } }