示例#1
0
 void Update()
 {
     if (SwitchColorTime > 0 && renderers.Count > 0)
     {
         time += direction * Time.deltaTime;
         if (time <= 0)//(renderers[0].material.color == color)
         {
             color2    = ColorAdjust.ConvertHsvToRgb(Random.Range(0, 360), Random.Range(0, 1f), 1);
             direction = 1;
         }
         else if (time >= SwitchColorTime)//(renderers[0].material.color == color2)
         {
             color     = ColorAdjust.ConvertHsvToRgb(Random.Range(0, 360), Random.Range(0, 1f), 1);
             direction = -1;
         }
         else
         {
             Color tempColor = Color.Lerp(color, color2, time / SwitchColorTime);
             for (int i = 0; i < renderers.Count; i++)
             {
                 if (renderers[i])
                 {
                     renderers[i].material.SetColor(ColorNameInShader, tempColor);
                 }
             }
         }
     }
 }
示例#2
0
 void Start()
 {
     color = ColorAdjust.ConvertHsvToRgb(Random.Range(0, 360), Random.Range(0, 1f), 1);
     if (renderers.Count < 1)
     {
         renderers.Add(this.GetComponent <Renderer>());
     }
     if (renderers.Count > 0)
     {
         for (int i = 0; i < renderers.Count; i++)
         {
             if (renderers[i])
             {
                 renderers[i].material.SetColor(ColorNameInShader, color);
             }
         }
     }
 }