- Home /
Question by
callumhutchy · Feb 05, 2014 at 11:29 PM ·
c#list
CS0103 The name 'List' does not exist in the current context
I was coding on one computer then i switched to laptop and suddenly i have an error which i can't for the life of me figure out what is going wrong. The error is the title,
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 MatchMaxUsers = 32;
public List<MPPlayer> PlayerList = new List<MPPlayer> ();
void Start ()
{
instance = this;
}
public void StartServer (string servername, string serverpassword, int maxusers)
{
MatchName = servername;
MatchPassword = serverpassword;
MatchMaxUsers = maxusers;
Network.InitializeServer (MatchMaxUsers, 2550, false);
Network.InitializeSecurity ();
}
void OnServerInitialized ()
{
Server_PlayerJoinRequest ("", Network.player);
}
void OnConnectedToServer ()
{
networkView.RPC ("Server_PlayerJoinRequest", RPCMode.Server,"", Network.player);
}
void OnPlayerDisconnected (NetworkPlayer id)
{
networkView.RPC ("Client_RemovePlayer", 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;
}
Comment
Best Answer
Answer by sooncat · Feb 06, 2014 at 03:05 AM
Line 68:
if (pl.PlayerNetwork = view)
Should be changed to "==".
I guess the problem is that: you write "if(a=b)" first and add "List" then. The editor don't rebuild the full code before you check the error.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
type or namespace name `List`1' could not be found 1 Answer
Why does this return a NullReferenceException? 0 Answers
Passing lists to serialize and deserialize methods for XML parsing 0 Answers
List Management. Removing from list and making sure item is not null 1 Answer