改变Cube的Shader下的Alpha值,实现Cube若隐若现的效果。
private float rotaSpeed = 5f;
private float timer = 1;
private bool flag = true;
private float delay = 4.0f;
void Update ()
{
if (timer <= 0)
{
flag = false;
}
if (flag == false)
{
timer += Time.deltaTime / delay;
}
if (timer >= 1)
{
flag = true;
}
if (flag == true)
{
timer -= Time.deltaTime / delay;
}
var render = Cube.GetComponent<Renderer>();
if (render != null)
{
var r = render.material.color.r;
var g = render.material.color.g;
var b = render.material.color.b;
render.material.color = new Color(r, g, b, timer);
}
//cube自转
Cube.transform.Rotate(new Vector3(0, -1, 0), Time.deltaTime * rotaSpeed);
}