- Home /
Question by
Albert-han · Jun 30, 2014 at 03:02 PM ·
networkmanagernotworking
Nested Class
Hi guys im having a problem with my script right now.I suddenly get this error i know nothing about.Googled it but I still dont get it. Error is Assets/Scripts/Network/Menu.cs(83,40): error CS0426: The nested type Player' does not exist in the type
NetworkManager'
Im using this script for my menu and network manager
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour {
private string CurMenu;
public string Name;
public string MatchName;
public int Players;
// Use this for initialization
void Start () {
CurMenu = "Main";
Name = PlayerPrefs.GetString("PlayerName");
}
// Update is called once per frame
void Update () {
}
void ToMenu(string menu){
CurMenu = menu;
}
void OnGUI(){
if (CurMenu == "Main")
Main();
if (CurMenu == "Host")
Host();
if (CurMenu == "Lobby")
Lobby();
if (CurMenu == "List")
MatchList();
}
private void Main(){
//if (GUI.Button(new Rect (0, 0, 128, 32), "Host A Match")) {
// ToMenu ("Host");
//}
if (GUI.Button (new Rect (0, 0, 128, 32), "Host a match")) {
ToMenu ("Host");
}
Name = GUI.TextField (new Rect (130, 0, 128, 32), Name);
if (GUI.Button(new Rect (260, 0, 128, 32), "Save"))
PlayerPrefs.SetString ("PlayerName", Name);
if (GUI.Button(new Rect (0, 33, 128, 32), "Server List")){
ToMenu ("List");
}
}
private void Host(){
if(GUI.Button(new Rect(0,0,128,32),"Start")){
NetworkManager.Instance.StartServer(MatchName,Players);
ToMenu("Lobby");
}
if(GUI.Button(new Rect(0,33,128,32),"Back")){
ToMenu("Main");
}
MatchName = GUI.TextField(new Rect(130,0,128,32),MatchName);
GUI.Label(new Rect(260,0,128,32),"Match name");
Players = Mathf.Clamp(Players,2,8);
GUI.Label(new Rect(260,32,128,32),"Amount Of Players");
if (GUI.Button (new Rect (145, 32, 32, 32),"+"))
Players ++;
GUI.Label (new Rect (192, 33, 64, 32), Players.ToString());
if (GUI.Button (new Rect (215, 33, 32, 32),"-"))
Players --;
}
private void Lobby(){
if (Network.isServer)
if(GUI.Button(new Rect(Screen.width - 128,Screen.height - 64,128,32),"Start")){
}
if(GUI.Button(new Rect(Screen.width - 128,Screen.height - 32,128,32),"Back")){
ToMenu("Host");
}
GUILayout.BeginArea (new Rect(0, 0, Screen.width / 2, Screen.height));
foreach(NetworkManager.Player pl in NetworkManager.Instance.PlayerList)
{
GUILayout.Label(pl.PlayerName);
}
GUILayout.EndArea ();
}
private void MatchList()
{
if (GUI.Button(new Rect(0,0,128,32), "Refresh"))
{
MasterServer.RequestHostList("Tut");
}
if (GUI.Button(new Rect(0,33,128,32), "Back"))
{
ToMenu ("Main");
}
GUILayout.BeginArea(new Rect(Screen.width/ 2, 0, Screen.width / 2, Screen.height), "Server List","box");
foreach (HostData hd in MasterServer.PollHostList())
{
GUILayout.BeginHorizontal();
GUILayout.Label(hd.gameName);
if(GUILayout.Button ("Connect"))
{
Network.Connect(hd);
ToMenu("Lobby");
}
GUILayout.EndHorizontal();
}
GUILayout.EndArea();
}
}
NetworkManager:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class NetworkManager : MonoBehaviour
{
public string PlayerName;
public string MatchName;
public static NetworkManager Instance;
public List<Player>PlayerList = new List<Player>();
public Player MyPlayer;
// Use this for initialization
void Start () {
Instance = this;
DontDestroyOnLoad(gameObject);
}
// Update is called once per frame
void Update () {
PlayerName = PlayerPrefs.GetString("PlayerName");
}
public void StartServer(string ServerName, int MaxPlayers)
{
Network.InitializeSecurity();
Network.InitializeServer (MaxPlayers, 25565, true);
MasterServer.RegisterHost("Tut", ServerName, "");
Debug.Log("Started Server");
}
void OnPlayerConnected(NetworkPlayer id)
{
//networkView.RPC ("Server_PlayerJoined", RPCMode.Server, PlayerName, id);
foreach (Player pl in PlayerList)
{
networkView.RPC("Client_PlayerJoined",id,pl.PlayerName, pl.OnlinePlayer);
}
}
void OnServerInitialized()
{
Server_PlayerJoined (PlayerName, Network.player);
}
void OnConnectedToServer()
{
networkView.RPC ("Server_PlayerJoined", RPCMode.Server, PlayerName, Network.player);
}
void OnPlayerDisconnected(NetworkPlayer id)
{
networkView.RPC ("Remove", RPCMode.All, id);
}
[RPC]
public void Server_PlayerJoined(string Username,NetworkPlayer id)
{
networkView.RPC("Client_PlayerJoined", RPCMode.All,PlayerName, id);
}
[RPC]
public void Client_PlayerJoined(string Username,NetworkPlayer id)
{
Player temp = new Player();
temp.PlayerName = Username;
temp.OnlinePlayer = id;
PlayerList.Add(temp);
if (Network.player == id)
{
MyPlayer = temp;
}
}
[RPC]
public void RemovePlayer(NetworkPlayer id)
{
Player temp = new Player ();
foreach(NetworkManager.Player pl in PlayerList)
{
if(pl.OnlinePlayer == id)
{
temp = pl;
}
}
if(temp !=null)
{
PlayerList.Remove (temp);
}
}
}
[System.Serializable]
public class Player{
public string PlayerName;
public NetworkPlayer OnlinePlayer;
}
If anyone know what this error means please help.thanks
Comment
Answer by Omberone · Jun 30, 2014 at 03:03 PM
The class "Player" is already declared in the Unity namespace.