- Home /
GUI issues
Im using photon unity networking and i can't figure out a good way of displaying all the games so you can choose one to join, currently you can search for a game and it will show up but what is the best way of spacing out the buttons because if two games have a similair name then they appear on top of each other, i don't see how i could do it efficiently, here is my code so far:
using UnityEngine;
using System.Collections;
public class RoomMechanics : MonoBehaviour {
public string InputField;
void Start ()
{
foreach (RoomInfo room in PhotonNetwork.GetRoomList())
{
//Debug.Log(room);
}
}
void OnGUI()
{
InputField=GUI.TextField (new Rect((Screen.width/2)-125,Screen.height/100,250,25),InputField);
foreach( RoomInfo room in PhotonNetwork.GetRoomList())
{
if(InputField!="")
{
if(room.name.ToString().Contains(InputField))
{
if(GUI.Button (new Rect((Screen.width/2)-125,300,250,50),room.name))
{
}
}
}
}
}
}
Answer by sumeetkhobare · Feb 17, 2015 at 10:07 PM
Buddy.. The Rect() function in Unity has the following definition:
Rect(float x,float y,float width,float height)
So. The problem in your code is that you are always specifying the same x and y location for the button of different rooms. You need to have some counter to give different positions for x or y or both.
For example:
float yPosition = 300;
foreach( RoomInfo room in PhotonNetwork.GetRoomList())
{
if(InputField!="")
{
if(room.name.ToString().Contains(InputField))
{
if(GUI.Button (new Rect((Screen.width/2)-125,yPosition,250,50),room.name))
{
}
}
yPosition += 75;
}
}
Updating the yPosition separates the buttons.
Mark the question solved, if this solves your problem.
PS: it has nothing to do with rooms having same name..
the problem with that it every frame it keeps increasing when we search for it
Your answer
Follow this Question
Related Questions
I'm having issues increasing my lives 2 Answers
Beginner need some help on Card Game 2 Answers
Chat GUI - Change Chat order? 1 Answer
getting udp package info inside unity (GlovePIE) 0 Answers
When Gui Text Clicked, Quit Game 2 Answers