IEnumerator AlternateStateFlashing(AlternateState alternateState) { float flashDuration = alternateState.flashingDuration; float step = -90.0f; Color col = alternateState.alternateStateColor; // This is multiplying by 6 in order to represent a "per second" option. No idea why the number 6. float flashingSpeed = alternateState.flashingSpeed * 6; while (alternateState.currentState == true) { if (alternateState.flashingDuration > 0) { flashDuration -= Time.deltaTime; if (flashDuration <= 0) { alternateState.SwitchState(false); } } step += Time.deltaTime * flashingSpeed; if (step > 270) { step -= 360; } col = Color.Lerp(alternateState.alternateStateColor, alternateState.flashingColor, (Mathf.Sin(step) + 1) / 2); alternateState.ApplyColor(col); yield return(null); } alternateState.ApplyColor(alternateState.defaultStateColor); }
void ReceiveFlashingRequest(AlternateState alternateState) { StartCoroutine(AlternateStateFlashing(alternateState)); }