Y
Y
Yuri2020-06-24 16:30:39
Working with color
Yuri, 2020-06-24 16:30:39

Recolor the platforms to the colors you like best using an array. How to write the script correctly?

Use a loop to step through the platforms.
Can you please help? I need to use a script to recolor my platforms in different colors. I tried everything and can not do it right:(
Below is my code...
````
public SpriteRenderer [] renderers;

void Start()
{
for( int i =0;i {
float r = UnityEngine.Random.value;
float g = UnityEngine.Random.value;
float b = UnityEngine.Random.value;
float a = UnityEngine.Random.value;
Color color = new Color(r ,g,b,a);
renderers[i].color = color;
renderers[0].color = Color.yellow;
renderers[1].color = Color.magenta;
renderers[2].color = Color.green;
renderers[3].color = Color.blue;
renderers[4].color = color.black;
}
}
````
I will be glad if you help me make the script right)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy, 2020-06-26
@uriy99

Here is the solution to this question:
public SpriteRenderer[] renderers;
void Start () {
foreach (SpriteRenderer render in renderers)
render.color = Color.HSVToRGB(Random.value, 1f, 1f);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question