错误说缺少功能

时间:2013-11-28 20:35:03

标签: c# unity3d

错误说' MPPlayer'无法找到,但我认为它被引用。

private void Menu_Lobby()
    {
        ScrollLobby = GUILayout.BeginScrollView(ScrollLobby, GUILayout.MaxWidth("200"));

        foreach (MPPlayer pl in MultiplayerManager.instance.PlayerList)
        {
            GUILayout.Box (pl.PlayerName);
        }

        GUILayout.EndScrollView();
    }

整页代码:

using UnityEngine;
using System.Collections;

public class MenuManager : MonoBehaviour
{
    public string CurrentMenu;

    public string MatchName = "";
    public string MatchPassword = "";
    public int MatchMaxPlayers = 20;

    private Vector2 ScrollLobby = Vector2.zero;

    void Start()
    {
        CurrentMenu = "Main";
        MatchName = "My Server " + Random.Range(0 , 100);
    }

    void OnGUI()
    {
        if (CurrentMenu == "Main")
            Menu_Main();
        if (CurrentMenu == "Lobby")
            Menu_Lobby();
        if (CurrentMenu == "Host")
            Menu_HostGame();
    }

    public void NavigateTo(string nextmenu)
    {
        CurrentMenu = nextmenu;
    }

    private void Menu_Main()
    {
        if (GUI.Button(new Rect(10,10,200,50), "Create Game"))
        {
            NavigateTo ("Host");
        }

        GUI.Label(new Rect(220, 10, 130, 30), "Player Name");
        MultiplayerManager.instance.PlayerName = GUI.TextField( new Rect(350, 10, 150, 30), MultiplayerManager.instance.PlayerName);
        if (GUI.Button (new Rect(510,10,100,30), "Save"))
        {
            PlayerPrefs.SetString("PlayerName", MultiplayerManager.instance.PlayerName);
        }
    }

    private void Menu_HostGame()
    {
        // Buttons Host Game
        if (GUI.Button(new Rect(10,10,200,50), "Back"))
        {
            NavigateTo("Main");
        }

        if (GUI.Button(new Rect(10,60,200,50), "Start Server"))
        {
            MultiplayerManager.instance.StartServer(MatchName, MatchPassword, MatchMaxPlayers);
        }

        GUI.Label(new Rect(220, 10, 130, 30), "Match Name");
        MatchName = GUI.TextField( new Rect(400, 10, 200, 30), MatchName);

        GUI.Label(new Rect(220, 50, 130, 30), "Match Password");
        MatchPassword = GUI.PasswordField( new Rect(400, 50, 200, 30), MatchPassword, '*');

        GUI.Label(new Rect(220, 90, 130, 30), "Match Max Players");
        GUI.Label(new Rect(400, 90, 200, 30), MatchMaxPlayers.ToString());
        MatchMaxPlayers = Mathf.Clamp (MatchMaxPlayers, 6, 20); // Allows min of 6 players and a max of 20 players.

        if (GUI.Button (new Rect(425,90,25,30), "+"))
            MatchMaxPlayers += 2; // Adds 2 players to the number
        if (GUI.Button (new Rect(450,90,25,30), "-"))
            MatchMaxPlayers -= 2; // Takes 2 players from the number
    }

    private void Menu_Lobby()
    {
        ScrollLobby = GUILayout.BeginScrollView(ScrollLobby, GUILayout.MaxWidth("200"));

        foreach (MPPlayer pl in MultiplayerManager.instance.PlayerList)
        {
            GUILayout.Box (pl.PlayerName);
        }

        GUILayout.EndScrollView();
    }

    void OnServerInitialized()
    {
        NavigateTo("Lobby");
    }

    void OnConnectedToServer()
    {
        NavigateTo("Lobby");
    }
}

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

foreach (MPPlayer pl in MultiplayerManager.instance.PlayerList)更改为foreach (var pl in MultiplayerManager.instance.PlayerList)并将鼠标悬停在VS var部分,以找出实际的类型名称。