Generation

generate functionTue, 06 Dec 2022

flash for 1 second the fade it and destroy

public void Flash(float duration) { StartCoroutine(FlashRoutine(duration)); } private IEnumerator FlashRoutine(float duration) { Color endColor = Color.white; Color startColor = new Color(1f, 1f, 1f, 0.5f); float t = 0f; while (t < duration) { t += Time.deltaTime; float lerp = Mathf.PingPong(t, duration) / duration; _flash.color = Color.Lerp(startColor, endColor, lerp); yield return null; } _flash.color = Color.clear; }

Questions about programming?Chat with your personal AI assistant