Unity3d Glow11中改变物体颜色脚本

该脚本展示如何使用Unity3d通过修改Mesh组件的颜色属性实现物体颜色的动态变化。具体方法是利用Time.timeSinceLevelLoad计算颜色的RGB值,并将其应用到Mesh上。
 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 低音炮可怕男子 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/DreamTime/p/5083238.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值