将下面代码绑在模型上面
var tempTime : float;
function Start()
{
tempTime = 0;
}
function Update () {
if(tempTime < 1)
{
tempTime = tempTime + Time.deltaTime;
}
if(renderer.material.color.a >0)
{
renderer.material.color.a = 1 - tempTime;
}
//print(renderer.material.color.a);
}
再把模型的shader改成透明的那一个Transparent/Diffuse
||||||||||||||||||||||||||||||||||||||| 模型变色 ||||||||||||||||||||||||||||||||||||
很简单。。。。
var colorStart = Color.red;
var colorEnd = Color.green;
var duration = 1.0;
var minimum = 0.0;
var maximum = 200.0;
function Update () {
var lerp = Mathf.PingPong (Time.time, duration) / duration;
renderer.material.color = Color.Lerp (colorStart, colorEnd, lerp);
transform.position.x = Mathf.Lerp(minimum, maximum, lerp);
}
本文介绍如何使用Unity实现模型的颜色渐变效果及模型位置的动态变化,通过简单的脚本控制,使得模型能够在指定时间内从一种颜色平滑过渡到另一种颜色,并同步改变其位置。
2957





