# how to set the first color of the list in the sprite

public List<SpriteRenderer> spritebox = new List<SpriteRenderer>();
public List<Color> colorbox = new List<Color>();

void Start() {
var renderer = GetComponent<SpriteRenderer>();
colorbox.Add(renderer.color);//I did so, except that it sends the color of the sprite to the list and in the last slot

spritebox = GetComponent<SpriteRenderer>();
colorbox = spritebox.color;//I did that too but it did not work

}


I'm trying to make the first color of the list in case the element 0 send the color to the sprite,would have any tips to help me?

In arrays and C# lists (which are wrappers for arrays that allow dynamic resizing) you should access elements by index in square brackets.

Examples:

This will get the first color from colorbox and store it in variable color:
Color color = colorbox[0];

This will assign color color to the first SpriteRenderer from spritebox:
spritebox[0].color = color;

You can put a variable or an expression inside brackets.

• Thank you it worked perfectly – Rangel Jun 13 '19 at 20:57