Hello, all i want to do is to create a random 10-char ID and then show a label with that as its text.
My code:
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour{
string[] CharacterArray = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","q","x","y","z","0","1","2","3","4","5","6","7","8","9"};
private string GameID = "";
private string RoomName = "";
void Start(){
StartCoroutine(GenerateRandomRoomID());
}
IEnumerator GenerateRandomRoomID(){
int Index = 1;
while(Index < 11){
System.Random rand = new System.Random();
int RandomNumber = rand.Next(0, 64);
Debug.Log(RandomNumber);
yield return new WaitForSeconds(1);
GameID = GameID + CharacterArray[RandomNumber]; // Make a random 10-character GameID
Index = Index + 1;
}
GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100 + 30,10,50), GameID);
}
void StartServer(){
Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
MasterServer.RegisterHost(GameID, RoomName);
}
void OnServerInitialized(){
Debug.Log("Server Initialized");
}
void OnGUI(){
RoomName = GUI.TextField(new Rect(10, 10, 200, 20), RoomName, 25);
if (!Network.isClient && !Network.isServer){
if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 50), "Start Server")){
StartServer();
}
}
}
}
There is no error message, but the label isn’t displayed either.