I am working on a Project in Unity where the Player on the Client side needs to connect to the Server running on another Unity Console Build. Anyways, on the Server side, there is a Client Class that handles all the Connections and Data Handling through a TCP Class but, there is also a Player Class, that needs to hold all the necessary information about the Player, like Display Width, Health Points and so on… Here is a sample of the Client Class:
public class Client
{
public Player player;
public TCP tcp;
public Client(int _clientId)
{
tcp = new TCP(id);
player = new Player();
}
public class TCP
{
//all the necessary variables for the workings of TCP
public TCP(int _id)
{
id = _id;
}
}
}
Here is a sample of the Player Class:
public class Player
{
public int id;
public string username;
public void Initialize(int _id, string _username)
{
id = _id;
username = _username;
}
}
I didn’t include all the code since it’s unnecessary for this topic.
My question is, how can I instantiate a Player class for every player that connects. How can I get the reference for every player and store it in an Array? I DON’T need to instantiate a Capsule or any Game Object, just the plain class to hold the information for each Player. I would need to be able to do something like this:
Client[] clients = new Client[20];
//calling the constructor in a for loop
clients*.Initialize(i, _username);*
That’s all. If for some reason the information I provided is not clear, I would happily add more details if needed. Thank you for your time.