Frage von cristiano2001, 10

Unity Wie kann ich die buttons zum map auswählen den Namen ändern?

Hier zu meinem script:using UnityEngine; using System.Collections;

[System.Serializable] public class Map { public string name; public string levelName; }

public class MainMenu : MonoBehaviour { public int curMenu = 0;

private string[] settings;
private int curIndex;

public float dif = 1;
HostData[] datas;
public Vector2 scroll;
private string gameName = "Server 666";

//You have to change this!
public string uniqueGameName = "MyUniqueGameName";

//After which time will the server list be refreshed ?
public float refreshTime = 10;

public Map[] maps;
public int curMapIndex;

void Start()
{
    InvokeRepeating("GetHostList", 0, refreshTime);
    settings = QualitySettings.names;
    Network.isMessageQueueRunning = false;
}

void GetHostList()
{
    MasterServer.RequestHostList(uniqueGameName);
}

void Update()
{
    dif = (Screen.width / 12.8f) / 100;
    datas = MasterServer.PollHostList();
}

void OnGUI()
{
    if (curMenu == 0)
    {
        if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 80 * dif, 200 * dif, 50 * dif), "Play"))
        {
            curMenu = 1;
        }
        if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 25 * dif, 200 * dif, 50 * dif), "Options"))
        {
            curMenu = 2;
        }
        if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 + 30 * dif, 200 * dif, 50 * dif), "Quit"))
        {
            Application.Quit();
        }

    }
    else if (curMenu == 1)
    {
        GUI.Box(new Rect(20 * dif, 20 * dif, 200 * dif, 200 * dif), "");
        GUILayout.BeginArea(new Rect(25 * dif, 25 * dif, 190 * dif, 190 * dif));
        gameName = GUILayout.TextField(gameName);
        if (GUILayout.Button("Start Server"))
        {
            Network.InitializeSecurity();
            Network.InitializeServer(17, 25001, /*!Network.HavePublicAddress()*/ true);
            MasterServer.RegisterHost(uniqueGameName, gameName);
        }
        if (GUILayout.Button("Select Map"))
        {
            curMenu = 5;
        }
        if (GUILayout.Button("Direct Connect"))
        {
            Network.Connect("127.0.0.1", 25001);
        }
        if (GUILayout.Button("Back"))
        {
            curMenu = 0;
        }
        GUILayout.EndArea();
        GUI.Box(new Rect(Screen.width - 400 * dif, 0, 400 * dif, Screen.height), "");
        GUILayout.BeginArea(new Rect(Screen.width - 400 * dif, 0, 400 * dif, Screen.height));
        GUILayout.Label("Avaiable Servers: " + datas.Length);
        scroll = GUILayout.BeginScrollView(scroll);
        foreach (HostData data in datas)
        {
            GUILayout.BeginHorizontal();
       
Antwort
von dosenbiiir, 2

Ich habe auf deine "gleiche" andere Frage ausführlicher geantwortet. Das gleiche Prinzip gilt auch hier wieder. Der Button-Text wird nach den Positions und - Größenangaben definiert.

Kommentar von cristiano2001 ,

ok;)

Keine passende Antwort gefunden?

Fragen Sie die Community

Weitere Fragen mit Antworten