Adding Classes to a List of classes

is there anyway of adding classes to a list such as List targets = new List(); of the players that are in the game ? of which i have these player’s as gameobject’s in an diffrent List ? i mean to get the classes of the players that are in game in a list so that i can detect if which player did what like change in states. so i want to detect change in states of players like (bool fly Run ect) that are in game and to add these specific player’s that have changed in states.! in an new list so that i can change or alter these list of players that have changed in state’s please help anyone ? :frowning:

That’s because one or more of your objects with the tag Player does not have a component of type Player attached, so the GetComponent call returns null. To get around this, you can either double check your tags, or add a null check before adding it to the list:

GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
LinkedList<Player> player_list = new LinkedList<Player>();

foreach(GameObject player in players)
{
    Player p = player.GetComponent<Player>();
    if(p)//if p is not null
        player_list.AddLast(p);
}