// Makes the object flash. void Flashing() { flashTimer += Time.fixedDeltaTime; durationTimer += Time.fixedDeltaTime; // Alternate the object renderer on and off, during the flash duration. if (durationTimer < duration) { if (flashTimer >= timeOn) { isOn = !isOn; flashingComponent.SetActive(isOn); flashTimer = 0f; } } else { // Reset the object to its initial state. isFlashing = false; if (onFlashEnded != null) { onFlashEnded(); } onFlashEnded = null; flashingComponent.SetActive(true); enabled = false; } }
/// <summary> /// Starts the object's flash effect, with a callback at the flash end. /// </summary> public void Flash(OnFlashEnded flashEndCallback) { isFlashing = true; isOn = true; // Reset the timers. flashTimer = 0f; durationTimer = 0f; onFlashEnded = flashEndCallback; enabled = true; }
/// <summary> /// Starts the object's flash effect, with a specific duration. /// </summary> public void Flash(float effectDuration, OnFlashEnded flashEndCallback) { duration = effectDuration; isFlashing = true; isOn = true; // Reset the timers. flashTimer = 0f; durationTimer = 0f; onFlashEnded = flashEndCallback; enabled = true; }