OnGUI button created by a foreach loop

Hi all, it seems like I cannot get the buttons to even display.
I don’t understand why… maybe because we cannot create GUI buttons inside of a foreach loop? I don’t see why this could be impossible…

foreach(string jjj in maps)
			{
			Debug.Log ("------------------- OK: " + jjj);
			//I correctly see all the jjj strings in the console, one per line. The problem is below.
					
				if(GUI.Button(new Rect(10,60 + yOffset,50,25), jjj)) 
				{	
					loadlevelname = jjj;
					Debug.Log ------------------LOADLEVELNAME: " + loadlevelname);
				}
				yOffset += 35;
					
			}

Man, it works fine.
Just check if your “maps” is full of content.

Here you are

using UnityEngine;
using System.Collections.Generic;

public class SomeScript : MonoBehaviour
{
	List<string> maps = new List<string>();
	
	void Start()
	{
		maps.Add("0");
		maps.Add("1");
		maps.Add("2");
		maps.Add("3");
		maps.Add("4");
		maps.Add("5");
	}
	
	void OnGUI()
	{
		float yOffset = 0f;
		
    		foreach(string i in maps)
   		{
        		if( GUI.Button (new Rect (25, 25+ yOffset, 150, 30), i) )
        		{
            			Debug.Log("pressed Item " + i);
        		}
			
        		yOffset += 35;
    		}
		
	}
}

I’m guessing based on comment in other answer:

“maps” refers to this string (before splitting): ;roger;maya;max;noel;jean;renault;sylvie

so if you code looks something like this it should work:

string[] maps;

maps = "roger;maya;max;noel;jean;renault;sylvie".Split(";"[0]);

or

s = "roger;maya;max;noel;jean;renault;sylvie";
maps = s.Split(";"[0]);

I know this is old but for anyone still looking for a similar answer, it’s because of this:

foreach (PhotonPlayer player in PhotonNetwork.playerList) {
			GUI.Label(new Rect(400, 15+ yOffset, 200, 25), player.name);
			yOffset += 30F;
		}

This is my code at the moment, if you put this inside a keypress you’ll notice that yOffset +=30F is scrolling ALL items, not adding to the height so they are under each other. I haven’t yet figured out a way to do this properly.

I know this is old but for anyone still looking for a similar answer, it’s because of this:

foreach (PhotonPlayer player in PhotonNetwork.playerList) {
			GUI.Label(new Rect(400, 15+ yOffset, 200, 25), player.name);
			yOffset += 30F;
		}

This is my code at the moment, if you put this inside a keypress you’ll notice that yOffset +=30F is scrolling ALL items, not adding to the height so they are under each other. I haven’t yet figured out a way to do this properly.