Change array components through loops with 4.6 gui

I have a level select with 50 levels, each of them have 3 stars (sprites) which can be activated, I have put all of the levels (images) in an array and would like to unlock them and give them their stars activated with 2 bools that use unity’s playerprefs, which are:

LevelStars + level

LevelS1 for example holds an int between 0 and 3.

and I have LevelC + level.

Which holds an int from 0 to 1 on the condition on the level if it’s completed or not, disabling the button or not.

I can’t really seem to figure out correctly how to do it so some help to get me going would be greatly appreciated, I previously did this with the old unity gui system using this code:

	if(PlayerPrefs.GetInt("LevelC"+i.ToString()) == 1){
						int levelStars = PlayerPrefs.GetInt("LevelS"+i);
						for(int j=0; j<levelStars; j++){
							//display of stars on level buttons
							GUI.Label(new Rect(280+(j*50), 40+(i*75-75), 50, 50), star);
						}
						//buttons with text
						if(GUI.Button (new Rect(100, 0+(i*75), 300, 75), "Level "+(i+1).ToString(), lvSelectStyle)){
							newLevel (i+1);
						}
					} else {
						//if level not finished lock and levle locked displayed
						GUI.Label(new Rect(100, 0+(i*75), 300, 75), "Level Locked", lvSelectStyle);
						GUI.DrawTexture(new Rect(360, 20+(i*75), 40, 48), levelLock);
					}
				}
			}

All of your UI elements should be built as GameObjects in the scene, or as prefabs. You can turn them on and off using Button.interactable or GameObject.SetActive. Make sure to add using UnityEngine.UI to the top of your scripts.

Here is how I would envision your hierarchy should look. Its up to you if you want to build this by hand or by script.

-Canvas
---Panel
-----Button1
-------Star1
-------Star2
-------Star3
-----Button2 //And so forth.

Your (very heavy pseudo) code to loop across them might look something like this

foreach (GameObject myButton in ButtonCollection){
    if(levelIsUnlocked){
        myButton.GetComponent<Button>().interactable = true;
    }
    if(star1IsUnlocked){
        myButton.transfrom.Find("Star1").SetActive(true);
    }
    // and so on
}

Note that with 4.6 you only need to run this code when the menu changes, not every frame.

I’ve also got a YouTube video that might help. The video is about creating a dropdown menu. But the general idea should work for your application.