Unity API常用方法和类详细讲解2
Unity API常用方法和类详细讲解2 019-使用Coroutine实现颜色动画渐变 void Update() { if (Input.GetKeyDown(KeyCode.Space)) { StartCoroutine(Fade()); } } IEnumerator Fade() { for (float i = 0; i <= 1; i += 0.1f) { cube.GetComponent().material.color = new Color(i, i, i,i); yield return new WaitForSeconds(0.1f); } } void Update() { if (Input.GetKeyDown(KeyCode.Space)) { StartCoroutine(Fade()); } } IEnumerator Fade() { while (true) { // cube.GetComponent<MeshRenderer>().material.color = new Color(i, i, i,i); Color color = cube.GetComponent<MeshRenderer>().material.color; Color newColor = Color.Lerp(color,Color.red,0.02f);