public IEnumerator Thanks () { fx = GameObject.FindObjectOfType<FX>(); fx.PageTake(); // Update float timeElapsed = 0f; float timeRatio = 0f; float duration = 2f; while (timeElapsed < duration) { timeRatio = timeElapsed / duration; materialThanks.SetFloat("_Alpha", timeRatio); timeElapsed += Time.deltaTime; yield return 0; } yield return new WaitForSeconds(5f); timeElapsed = 0f; while (timeElapsed < duration) { timeRatio = timeElapsed / duration; materialThanks.SetFloat("_Alpha", 1f - timeRatio); timeElapsed += Time.deltaTime; yield return 0; } }