Hi, I have this script which connects to SmartFox. I want to put the login section inside of a GUIwindow box so I can center it and make it look nice. But I am unable to figure this out with that Line 16 if (smartFox.IsConnected()) { part in the way. However, I need that to still remain.
void OnGUI() {
// server IP in bottom left corner
GUI.Label(new Rect(10, Screen.height-25, 200, 24), "Server: " + serverIP);
// quit button in bottom right corner
if ( Application.platform != RuntimePlatform.WindowsWebPlayer ) {
if ( GUI.Button(new Rect(Screen.width-150, Screen.height - 50, 100, 24), "Quit") ) {
smartFox.Disconnect();
UnregisterSFSSceneCallbacks();
Application.Quit();
}
}
// Show login fields if connected and reconnect button if disconnect
if (smartFox.IsConnected()) {
GUI.Label(new Rect(140, 40, 130 ,100), "Username: ");
username = GUI.TextField(new Rect(25, 60, 375, 30), username, 25);
if ( GUI.Button(new Rect(25, 160, 175, 50), "Login") || (Event.current.type == EventType.keyDown Event.current.character == '\n')) {
smartFox.Login(zone, username, "");
}
} else {
if ( GUI.Button(new Rect(25, 160, 175, 50), "Reconnect") || (Event.current.type == EventType.keyDown Event.current.character == '\n')) {
Application.LoadLevel("sc_City");
}
}
// Draw box for status messages, if one is given
// Contains some logic to parse message of multiple lines if necessary
if (statusMessage.Length > 0)
{
int boxLength = 61; // define length of status box
int messageLength = statusMessage.Length; // get length of status message
string originalMessage = statusMessage; // copy message in to work string
string formattedMessage = ""; // define output message string
int i = 0;
while (i + boxLength < messageLength) // iterate and add newline until over length
{
formattedMessage = formattedMessage + originalMessage.Substring(i,boxLength) + "\n";
i = i + boxLength;
}
// add last piece of original message
formattedMessage = formattedMessage + originalMessage.Substring(i, boxLength - (i + boxLength - messageLength));
// draw status box with message
GUI.Box (new Rect (Screen.width - 420,10,400,48), formattedMessage);
}
}
I am aware that is the line of code that goes there.
In your example, on line 4, you took out the "if (smartFox.IsConnected()) { ". Like I said, I still need that line of code to remain. I could not figure out how to insert the Gui.Window and keep that code too.