list.Add() not working

I have a for loop, adding objects to a list. But it only works the first time, and then just stops functioning. Everything else in the loop works.

public IEnumerator spawnReal(){
			for(int y = 0;y < 8;y++){
				for(int x = 0;x < 8;x++){
					Color color = abilitiesInLevel[level].levelImage.GetPixel(x,y);
					if(color != Color.white){
						GameObject obj = Instantiate(projectile,new Vector3((x - 4) * 0.6F,5,-6),Quaternion.identity) as GameObject;
						orb Orb = obj.GetComponent<orb>();
						Orb.durability = (int)Mathf.Round(color.r * 5.1F);
						Orb.type = (int)Mathf.Round(color.g * 5.1F);
						Orb.speed = (int)Mathf.Round(color.b * 5.1F);
				yield return new WaitForSeconds(0.3F);
			yield break;

Are you sure that is your exact code? Coz the error is very simple. This code should throw compiler errors.

Check where you declare and initialize orb

Orb orb = obj.GetComponent<orb>();
orb.durability = (int)Mathf.Round(color.r * 5.1F);
orb.type = (int)Mathf.Round(color.g * 5.1F);
orb.speed = (int)Mathf.Round(color.b * 5.1F);

Variable type comes before variable name in the declaration. And you are using the Class name itself to manipulate values and add it to the list.

Having analyzed my code several times, I found that because of forgetting a bracket the full loop was larger than I thought and included: “yield break.”

I suspect that you have selected the “collapse” button in the console window. It will collapse the same debug.Log messages into one. So the code works fine, but you misinterpreted your debug results.