Setting an gameobjects parent

Options
We are working on an item system where you can equip weapons etc. for this we set the weapons parent to the placeholder. But when I try using RPCs or RaiseEvents to set the parent of the object for all the other clients it doesn't set the parent, it only works for the local client.

These are both ways I tried to accomplish the parenting:
https://pastebin.com/CEAWP5gr

Answers

  • WTler
    WTler
    edited July 2017
    Options
    The Problem is with the instantiation. The prefabs Player and Sword are assigned to the variables player and sword for the client who instantiated it, bur not for the other clients. You need to call OnPhotonInstantiate(PhotonMessageInfo info) on a script on your prefabs. Then you can do
    public GameObject sword;
    
    void OnPhotonInstantiate(PhotonMessageInfo info){
          sword=this.gameObject;
    }
    and on your instantiaton script you can call GameObject sword= FindObjectOfType<SwordScript>.sword; and do stuff with it.