How to make RANDOM COLOR on shader
I use Retro Pixel https://www.assetstore.unity3d.com/#!/content/16314 shader
I use 8 colors, and I want to change them color at random every time
I wrote this;
public Color color0 = Color.black; public Color color1 = Color.white; public Color color2 = new Color(Random.value, Random.value, Random.value, 1.0f); public Color color3 = new Color(Random.value, Random.value, Random.value, 1.0f); public Color color4 = new Color(Random.value, Random.value, Random.value, 1.0f); public Color color5 = new Color(Random.value, Random.value, Random.value, 1.0f); public Color color6 = new Color(Random.value, Random.value, Random.value, 1.0f); public Color color7 = new Color(Random.value, Random.value, Random.value, 1.0f);
but not changed colors every time
How should I do
Answer by TBruce · Oct 02, 2016 at 07:05 PM
The follow script will change the colors every time.
 using UnityEngine;
 using System.Collections;
 using AlpacaSound;
 
 public class TestRetroPixel : MonoBehaviour
 {
     public RetroPixel retroPixel;
     
     // Use this for initialization
     void Start ()
     {
         GetRandomColors();
     }
     
     public void GetRandomColors ()
     {
         if (retroPixel != null)
         {
             for (int i = 0; i < 7; i++)
             {
                 switch (i)
                 {
                     case 0:
                         retroPixel.color0 = Color.black;
                         break;
                     case 1:
                         retroPixel.color1 = Color.white;
                         break;
                     case 2:
                         retroPixel.color2 = GetRandomColor();
                         break;
                     case 3:
                         retroPixel.color3 = GetRandomColor();
                         break;
                     case 4:
                         retroPixel.color4 = GetRandomColor();
                         break;
                     case 5:
                         retroPixel.color5 = GetRandomColor();
                         break;
                     case 6:
                         retroPixel.color6 = GetRandomColor();
                         break;
                     case 7:
                         retroPixel.color7 = GetRandomColor();
                         break;
                 }
             }
         }
     }
     
     Color GetRandomColor ()
     {
         Color color = Color.black;
 
         while ((color == Color.black) || (color == Color.white))
         {
             color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
         }
         return color;
     }
 }
 
               Attached is a Unity package that tests RetroPixels.
@UNBLVERS Could you please be so kind as to click the "Accept" button above to accept the answer if you have found this helpful?
Your answer