Help with random player sytem

Options
iamE
iamE
I got this code when I asked a question earlier about selecting a random player and TaggedPlayer is a string so I can't get a .GetComponent and stuff from it. Does anyone know how to fix this?

using System.Collections.Generic;

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

We can call PlayerConnected

void OnPhotonPlayerConnected(){
if (!PlayerList.Contains (PhotonNetwork.playerName)) {
PlayerList.Add (PhotonNetwork.playerName);
}
}

Next We Need A Pick Random Method to Invoke

void TagRandomPlayer(){
int PlayerListRange = PlayerList.Count;
System.Random Rand = new System.Random ();
int RandomPick = Rand.Next (0, PlayerListRange);
string TaggedPlayer = PlayerList [RandomPick];
}

Comments

  • iamE
    Options
    Can someone please help?
  • Tobias
    Options
    Sorry, we can only help with coding problems when we really have the time for it. At the moment, we're too busy to write working code for anyone else. For us it's way faster to write pseudo code and let you do the exact implementation.
    You might be faster learning a bit more about C# programming and about fixing any errors you get when you compile things.
    You don't even write what exactly is going wrong. You just paste pseudo-code.
  • iamE
    Options
    Tobias wrote:
    Sorry, we can only help with coding problems when we really have the time for it. At the moment, we're too busy to write working code for anyone else. For us it's way faster to write pseudo code and let you do the exact implementation.
    You might be faster learning a bit more about C# programming and about fixing any errors you get when you compile things.
    You don't even write what exactly is going wrong. You just paste pseudo-code.
    I wrote that I'm picking a random player and that's the code there. But, I can't run GetComponent on the picked player which in this code is a string(TaggedPlayer). I need to be able to enable and disable scripts on the randomly chosen player.