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
}
}
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.