Add action to button

Ok so I have this code that lists the current active servers:

for (var game : RoomInfo in PhotonNetwork.GetRoomList())
	{  	
		GUILayout.Button(game.name + " - " + game.playerCount + "/" + game.maxPlayers + " " + "Ping: " + PhotonNetwork.GetPing());
	}

My question is how do I make the buttons clickable. I want to click on them and join the correspondent server. I hope you understand what I am trying to say.

Thank you.

You would use an “if” statement for the button. Instead of

GUILayout.Button…

Use

if(GUILayout.Button......
{
    DoSomething();
}

Here is the Unity Script Reference for GUILayout.Button