低音炮可怕男子

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 /*
 2  * 通过改变Mesh组件的Color来改变颜色
 3  * */
 4 using UnityEngine;
 5 using System.Collections;
 6 
 7 public class ColorChangerVertex : MonoBehaviour
 8 {
 9  
10     Mesh mesh;
11     //定义一个颜色数组,Color数组中有4个数,RGBA
12     Color[] meshColors;
13 
14     void Start() {
15         mesh = GetComponent<MeshFilter>().mesh;
16         meshColors = new Color[mesh.vertices.Length];
17     }
18 
19     // Update is called once per frame
20     void Update() {
21         //让RGB随关卡加载时间改变Time.timeSinceLevelLoad
22         for (int i=0; i<meshColors.Length; ++i) {
23             float offset = mesh.vertices[i].magnitude;
24             float r = Mathf.Abs(Mathf.Sin(Time.timeSinceLevelLoad  + offset));
25             float g = Mathf.Abs(Mathf.Sin(Time.timeSinceLevelLoad * 0.45f + offset));
26             float b = Mathf.Abs(Mathf.Sin(Time.timeSinceLevelLoad * 1.2f + offset));
27             Color newColor = new Color(r,g,b);
28 
29             meshColors [i] = newColor;
30         }
31         mesh.colors = meshColors;
32 
33     }
34     
35 }

 

posted on 2015-12-28 17:23  低音炮可怕男子  阅读(1637)  评论(0编辑  收藏  举报