Adding PlayerPrefab(Clone) to a list

I have a List

public List<RPS_Position> positionScript = new List<RPS_Position> (); //List of RPS_Position scripts in the scene

My Players are prefabs and are instantiated by script

player = PhotonNetwork.Instantiate(playerModel[playerIndex].name, spawnPoints[spawnIndex].position, spawnPoints[spawnIndex].rotation, 0);

how can i add the players that are active in scene to the List?
It could be that i have 1 - 8 Players with TAG “Player” and TAG “OtherPlayer”

my try so far:

void Start () {

        //AddRiders
        AddRiders();

        //Iterates through all PositionSensors to find the lowest and highest position numbers
        float firstNumber = Mathf.Infinity; //Temporary variables changed through the iterations.
        float lastNumber = -Mathf.Infinity;
        foreach (RPS_PositionSensor pos in allPositionSensors) {
            if (pos.thisPosition < firstNumber) {
                firstNumber = pos.thisPosition; //Finds minimum number
            }
            if (pos.thisPosition > lastNumber) {
                lastNumber = pos.thisPosition; //Finds maximum number
            }
        }
        firstPositionNumber = firstNumber;
        lastPositionNumber = lastNumber;
    }

    public void AddRiders()
    {
        int playerIndex = (GameObject.FindGameObjectsWithTag("Player","OtherPlayer");  //Ahhhh
       
        for ( int i = 0; i < positionScript.Length; i++)  ///Nooo
           
        //help
    }

}

Why not just maintain list on your own?

Add them to the list after you’ve instantiated them, access that list from anywhere.

I dont know to do that:
I have so far now:

public void AddRiders()
    {
        foreach(RPS_Position _player in positionScript)
        {

            RPS_Position _newPlayer;
            _newPlayer = GameObject.FindGameObjectWithTag("Player");
            positionScript.Add(_newPlayer);
        }
    }

but stutter one the error:

Cannot implicitly convert type 'UnityEngine.GameObject' to 'RPS_Position'

Ok i can use 2 tags but still stutter in the conversion:

public void AddRiders()
    {
        foreach(RPS_Position _player in positionScript)
        {

            GameObject[] tag_1 = GameObject.FindGameObjectsWithTag("Player");
            GameObject[] tag_2 = GameObject.FindGameObjectsWithTag("OtherPlayer");
            GameObject[] final_array = tag_1.Concat(tag_2).ToArray();

            RPS_Position _newPlayer;
            _newPlayer = final_array;
            positionScript.Add(_newPlayer);
        }
    }

Store it after instantiation. Like

public static List<Player> Players = new List<Player>();

// Where you're instantiating
// grab a Player or replace Player with GameObject type
player = PhotonNetwork.Instantiate(playerModel[playerIndex].name, spawnPoints[spawnIndex].position, spawnPoints[spawnIndex].rotation, 0);
Players.Add(player);

// Dont forget to clear list upon game restart

Access that Players list from anywhere by the class Class.Players.
Or use a singleton if you like.

Grab your RPS_Position via .GetComponent<RPS_Position> from the players of that list.

And stop using tags. They’re completely useless.

But i think i have the List already!?

for (int i = 0; i < PhotonNetwork.PlayerList.Length; i++)

I can access from there, or not?

So, now i need to convert from int:

public void AddRiders()
    {
        for (int i = 0; i < PhotonNetwork.PlayerList.Length;)
                   
             positionScript.Add(i);

Small Steps:

 GameObject[] tag;
            GameObject[] tag_2;


            tag = GameObject.FindGameObjectsWithTag("Player");
            tag_2 = GameObject.FindGameObjectsWithTag("OtherPlayer");


            for (int i = 0; i < tag.Length; i++)

            {
                positionScript.Add(tag[i].GetComponent<RPS_Position>());
                Debug.Log ("found TAG");
            }

            for (int i = 0; i < tag_2.Length; i++)

            {
                positionScript.Add(tag_2[i].GetComponent<RPS_Position>());
            }

When i put this in an Update function it fills me the list, but not with the Player :frowning: