KeyNotFoundException: The given key was not present in the dictionary
Получаю ошибку, когда попадаю по любому объекту на сцене:
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <695d1cc93cca45069c528c15c9fdd749>:0)
GameManager.GetPlayer (System.String _playerID) (at Assets/Scripts/GameManager.cs:39)
PlayerShoot.CmdPlayerShot (System.String _playerID, System.Int32 _damage) (at Assets/Scripts/PlayerShoot.cs:51)
PlayerShoot.CallCmdPlayerShot (System.String _playerID, System.Int32 _damage) (at <15d409b66be84a30afe6c008fd1cb636>:0)
PlayerShoot.Shoot () (at Assets/Scripts/PlayerShoot.cs:41)
PlayerShoot.Update () (at Assets/Scripts/PlayerShoot.cs:29)
Вот код самого скрипта:
using UnityEngine;
using System.Collections.Generic;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public MatchSettings matchSettings;
private void Awake()
{
if (instance != null)
{
Debug.LogError("More than one GameManager in scene.");
} else
instance = this;
}
#region Player tracking
private const string PLAYER_ID_PREFIX = "Player ";
private static Dictionary<string, Player> players = new Dictionary<string, Player>();
public static void RegisterPlayer(string _netID, Player _player)
{
string _playerID = PLAYER_ID_PREFIX + _netID;
players.Add(_playerID, _player);
_player.transform.name = _playerID;
}
public static void UnRegisterPlayer (string _playerID)
{
players.Remove(_playerID);
}
public static Player GetPlayer (string _playerID)
{
return players[_playerID];
}
//void ingui()
//{
// guilayout.beginarea(new rect(200, 200, 200, 500));
// guilayout.beginvertical();
// foreach (string _playerid in players.keys)
// {
// guilayout.label(_playerid + " - " + players[_playerid].transform.name);
// }
// guilayout.endvertical();
// guilayout.endarea();
//}
#endregion
}
