Name gameobjects in array C#

Hey guys,

I want to name each item in an array Planet + it’s index number, but since my C# knowledge isn’t that big… yet, I would like to ask you guys for some help. I did do some research online, but couldn’t really find what I was looking for.

Code:

GameObject[] planetsList = GameObject.FindGameObjectsWithTag("Planet");
        for (int j = 0; j < planetsList.Length; j++)

Thanks in advance!
Christian

{
planetsList[j].name = "Planet " + j;
}

Thanks!

Edit: when I put new items in the planetsList, instead of using anything below 5, it’ll just go to 6-11 range. I’ve tried using Array.Clear, but that doesn’t change anything :confused:

If it’s a list maybe you should make it a list instead of an array:

List<GameObject> planetList = GameObject.FindGameObjectsWithTag("Planet");

An array has a fixed size so once it’s initialized you won’t be able to add new planets to it. A list can grow as needed.