Change Main Color to Predefined colors randomly

I am making a simple memory game that records colors and times the color is displayed.
Previously, i asked a question here and built my code like this… What i wanted to do is to display objects.

#pragma strict
public var OnScreen : Texture2D[] = new Texture2D[8];
public var timeBetweenImages = 5.0 / 8.0;
function Start () {
// Shuffle Images
var temp : Texture2D;
for (var i = 0; i < OnScreen.Length-1; i++) {
var j = Random.Range(i, OnScreen.Length);
temp = OnScreen*;*

OnScreen = OnScreen[j];
OnScreen[j] = temp;

function DisplayImages () {
var i = 0;
while(true) {
renderer.material.mainTexture = OnScreen*;*
i = (i + 1) % OnScreen.Length;
yield WaitForSeconds(0.6);
I am suppposed to display all images once but the code is built for a loop i think…
I want to predefine 8 colors and change them as the image changes. This will not have any relativity to the object. In the end, the player is supposed to answer number of times the color has been displayed out of three options…
Currently, everything till the image display is fine… However, I am getting this ‘unmapped’ look. How do i go about this whole thing?



Assuming you declare an initialize in the inspector an array of colors:

 public var colors : Color[];

You can set the renderer to a random color by:

 renderer.material.color = colors[Ransom.Range(0, colors.Length)];

Note if you only want to go through the images once, you can change the DisplayImages() function to:

function DisplayImages () {
    for (var i = 0; i < OnScreen.Length; i++) {
        renderer.material.mainTexture = OnScreen*;*

yield WaitForSeconds(0.6);