IEnumerator IFlash(float flashDuration, float fadeOutDuration) { flash.SetActive(true); flashCG.alpha = 1f; audioMixer.SetFloat("FlashbangVolume", -80f); flashAudioSource.volume = flashSoundVolume; flashAudioSource.Play(); float t = Time.time; while (Time.time < t + flashDuration) { yield return(0); } float startTime = Time.time; while (Time.time < startTime + fadeOutDuration) { float i = Mathf.InverseLerp(startTime + fadeOutDuration, startTime, Time.time); flashCG.alpha = i; audioMixer.SetFloat("FlashbangVolume", GameController.LinearToDecibel(1f - i)); flashAudioSource.volume = i * flashSoundVolume; yield return(0); } StopFlash(); }
IEnumerator ISmallFlash() { flash.SetActive(true); flashCG.alpha = 0.5f; audioMixer.SetFloat("FlashbangVolume", -80f * smallFlashMultiplier); flashAudioSource.volume = flashSoundVolume * smallFlashMultiplier; flashAudioSource.Play(); float startTime = Time.time; while (Time.time < startTime + 0.5f) { float i = Mathf.InverseLerp(startTime + 0.5f, startTime, Time.time); flashCG.alpha = i * 0.5f; audioMixer.SetFloat("FlashbangVolume", GameController.LinearToDecibel(1f - i) * smallFlashMultiplier); flashAudioSource.volume = i * (flashSoundVolume * smallFlashMultiplier); yield return(0); } StopFlash(); }