Unique object network ID

Options
Hello! I would like to make a script, which will look out for new players, joining the server, and add them to the array (list), in such a way, that if a player enters the server he/she receives the updated information (with already joined players).

I think RPC is the only way to do it properly (am I wrong?).

With some help I've wrote a script and attached it to an object in the scene, which has PhotonView component enabled (owner: Scene fixed, view ID: 1, ObeserveOption: off, Obeserved Components: none). The script updates adds element to the array via RPC, till the PhotonViewID comparisson is run. Once it's run, the script determines that the object which was instantiated on the other client has the same PhotonViewID as we have, hence it is the same (which is wrong) and stops adding it to the array.

Could you please suggest why is it so? And how to compare different objects instantiated via the Network? Thank you very much!


using UnityEngine; using System.Collections; using System.Collections.Generic; public class instantiate_spectator_at_runtime : MonoBehaviour { public List<GameObject> myList; public PhotonView photonView; // Use this for initialization void Start () { } void Update () { if (Input.GetKeyDown (KeyCode.A)) { Debug.Log("PhotonViewID" + gameObject.GetComponent<PhotonView>().viewID); } if (Input.GetKeyDown (KeyCode.W)) { photonView = this.gameObject.GetComponent<PhotonView>(); photonView.RPC("addtolist", PhotonTargets.AllBuffered); } } [PunRPC] public void addtolist(){ if (myList.Contains (this.gameObject)) { for (int i = 0; i < myList.Count; i++){ if(myList[i].gameObject.GetComponent<PhotonView>().viewID == photonView.viewID){ Debug.Log("it's the same"); break; } else myList.Add(this.gameObject); } } else myList.Add(this.gameObject); } }