Search Unity

Hello i have proble with instantiate photon

Discussion in 'Scripting' started by gagac42, Dec 10, 2018.

  1. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    aaa
     
    Last edited: Dec 21, 2018
  2. Reeii

    Reeii

    Joined:
    Feb 5, 2016
    Posts:
    91
    Well, it's only logical. If you want to only happen it once, you can check:

    Code (CSharp):
    1. if (photonView.IsMine) {
    2.  
    3. }
     
  3. Reeii

    Reeii

    Joined:
    Feb 5, 2016
    Posts:
    91
    Well, that shouldn't happen since PhotonNetwork.Instantiate instantiates the object on each client. Can you post your code again?
     
  4. Reeii

    Reeii

    Joined:
    Feb 5, 2016
    Posts:
    91
    What is this class after all? How many instances of it are in the scene and what is it attached to?
     
  5. Reeii

    Reeii

    Joined:
    Feb 5, 2016
    Posts:
    91
    Sorry that I answer so late.
    You could try making an RPC that instantiates the view id of the PhotonView of the parent object (a PhotonView has to be attached to it). Then, the RPC finds the parent object using the view id, instantiates the cloth object and sets the parent of it on all clients.
    Code (CSharp):
    1.         public void Start() {
    2.             if (photonView.IsMine) {
    3.                 photonView.RPC("RPC_InstantiateCloth", RpcTarget.All, photonView.ViewID);
    4.             }
    5.         }
    6.  
    7.         [PunRPC]
    8.         private void RPC_InstantiateCloth(int parentViewId) {
    9.             GameObject parentObject = PhotonView.Find(parentViewId).gameObject;
    10.             GameObject clone = Instantiate(Top[topNum].name, parentObject.transform.position, parentObject.transform.rotation, 0);
    11.             clone.transform.parent = parentObject.transform;
    12.         }
     
  6. Reeii

    Reeii

    Joined:
    Feb 5, 2016
    Posts:
    91
    Does the RPC get called instantly when a player joins? If yes, use PhotonTargets.AllBuffered in the RPC call to let it be sent to the other players who join afterwards too.