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);
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 [79390-testretropixel.zip|79390] that tests RetroPixels.