I asked this question earlier in the comments of another question of mine, but it was closed. What’s wrong with this code? It doesn’t run. I don’t know why. Can you please help? By the way I’m new to programming so I’m sorry if it’s painfully obvious.
Other Question
public List<string> PlayerList = new List<string>();
public bool offlineMode = false;
Dictionary<string, GameObject> PlayerDictionary = new Dictionary<string, GameObject>();
public static void RegisterPlayerObject (string playerName, GameObject playerGameObject) {
NetworkManager nm = GameObject.Find("Manager").GetComponent<NetworkManager>();
nm.PlayerDictionary.Add (playerName, playerGameObject);
nm.PlayerList.Add(playerName);
}
void OnPhotonPlayerConnected(){
if (!PlayerList.Contains (PhotonNetwork.playerName)) {
PlayerList.Add (PhotonNetwork.playerName);
}
}
void TagRandomPlayer(){
int PlayerListRange = PlayerList.Count;
System.Random Rand = new System.Random ();
int RandomPick = Rand.Next (0, PlayerListRange);
string TaggedPlayer = PlayerList [RandomPick];
Knife knife = PlayerDictionary [TaggedPlayer].GetComponent<Knife>();
((MonoBehaviour)knife.GetComponent("Knife")).enabled = true;
}
IEnumerator OnNewRound(){
yield return new WaitForSeconds(10);
TagRandomPlayer ();
Debug.Log ("Hello");
}
// Use this for initialization
void Start () {
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
Connect ();
OnNewRound ();
}