CS0030 ERROR !

That is the error :
Assets/Scripts/MenuManager.cs(81,33): error CS0030: Cannot convert type MultiplayerManager.MPPlayer' to MPPlayer’

That is MenuManager.cs

using UnityEngine;
using System.Collections;

public class MenuManager : MonoBehaviour
{
	public string CurrentMenu;

	public string MatchName = "";
	public string MatchPassword = "";
	public int MatchPlayers = 12;

	private Vector2 ScrollLobby = Vector2.zero;

		void Start()
	{
		CurrentMenu = "Main";
		MatchName = "War Room " + Random.Range (0, 5000);
	}

	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), "Play"))
		{
			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), "Apply")) 
		{
			PlayerPrefs.SetString("PlayerName", MultiplayerManager.instance.PlayerName);
		}
	}

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

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

				}

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

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

				GUI.Label (new Rect (220, 90, 130, 30), "Room Max Players");
				GUI.Label (new Rect (400, 90, 200, 30), MatchPlayers.ToString ());
				MatchPlayers = Mathf.Clamp (MatchPlayers, 8, 12);

				if (GUI.Button (new Rect (425, 90, 25, 30), "+"))
						MatchPlayers += 2;
				if (GUI.Button (new Rect (450, 90, 25, 30), "-"))
						MatchPlayers -= 2;
		}
	
	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 OnServerInitializated()
	{
		NavigateTo("Lobby");
	}

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

And that is MultiplayerManager.cs

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MultiplayerManager : MonoBehaviour 
{
	public static MultiplayerManager instance;
	public string PlayerName;
	private string MatchName = "";
	private string MatchPassword = "";
	private int MatchPlayers = 12;
	public List<MPPlayer> PlayerList = new List<MPPlayer>();
	
	void Start()
	{
		instance = this;
		PlayerName = PlayerPrefs.GetString("PlayerName");
	}

	public void StartServer(string servername, string serverpassword, int maxusers)
	{
				MatchName = servername;
				MatchPassword = serverpassword;
				MatchPlayers = maxusers;
				Network.InitializeServer (MatchPlayers, 2550, false);
		MasterServer.RegisterHost ("DeathMatch", MatchName, "");
				//Network.InitializeSecurity ();
	}

	void OnServerInitialized()
	{
		Server_PlayerJoinRequest(PlayerName, Network.player);
	}

	void OnConnectedToServer()
	{
		networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, PlayerName, Network.player);
	}

	void OnPlayerDisconnected(NetworkPlayer id)
	{
		networkView.RPC("Server_PlayerJoinRequest", RPCMode.All, id);
	}

	[RPC]
	void Server_PlayerJoinRequest(string playername, NetworkPlayer view)
	{
		networkView.RPC("Client_AddPlayerToList", RPCMode.All, playername, view);
	}

	[RPC]
	void Client_AddPlayerToList(string playername, NetworkPlayer view)
	{
		MPPlayer tempplayer = new MPPlayer();
		tempplayer.PlayerName = playername;
		tempplayer.PlayerNetwork = view;
		PlayerList.Add(tempplayer);
	}

	[RPC]
	void Client_RemovePlayer(NetworkPlayer view)
	{
		MPPlayer temppl = null;
		foreach(MPPlayer pl in PlayerList)
		{
			if (pl.PlayerNetwork == view)
			{
				temppl = pl;
			}
		}
		if(temppl != null)
		{
			PlayerList.Remove(temppl);
	}
}

public class MPPlayer
{
	public string PlayerName = "";
	public NetworkPlayer PlayerNetwork;
	}
}

Help please .

For the love of Computer Science could you please Format your Code using the 101010 Button so that it is somewhat more readable.

–

1 Answer

1

You have 2 Errors.

In MenuManager.cs. When you try and define the pl Variable as of type MPPlayer, the type does not exist in the current context, you need to reference it from where it exists in the MultiplayerManager class. As such.

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

In MultiplayerManager.cs. When you define your List PlayerList, you must provide the Type you wish to handle. I can safely assume the Type you want your PlayerList to be is MPPlayer. As such.

public List<MPPlayer> PlayerList = new List<MPPlayer>();