Adding instantiated players

Options

Not working


I want to access Transform all the players in the room.


How?


public class GameManager : MonoBehaviour

{

  PhotonView pv;

  List<Transform> playerList = new List<Transform>();


  private void Awake()

  {

    pv = GetComponent<PhotonView>();

  }


  void Start()

  {

    GameObject player = PhotonNetwork.Instantiate("Prefabs/Player", Vector3.zero, Quaternion.identity);


    AddPlayer(player);


    pv.RPC("AddPlayer", RpcTarget.All, player);


  }


  [PunRPC]

  private void AddPlayer(GameObject p)

  {

    this.playerList.Add(p.transform);

  }

}

Answers

  • Tobias
    Options

    You could put a script on prefabs with PhotonViews. Once they get instantiated, the new object can put itself into a list (in your code) so you can iterate over it.