Instantiating child Gameobject over the network

Hi all,

I am trying to Instantiate a prefab and attach it as a child gameobject to already networked gameobject.

So far I have code below:
GameObject go = PhotonNetwork.Instantiate (Path.Combine ("Prefabs", "Figurehead", prefab.name),
pos.transform.position,
pos.transform.rotation);
go.transform.parent = pos.transform;

I have a Pirate Ship and I am trying to attach a ship component after the ship already Instantiated.
Anyone how I could do that?

Answers

  • To use PhotonNetwork.Instantiate you need to place your prefab in Ressources folder so your hierarchy would be Assets/Ressources/Prefabs/Figurehead/prefabName and to use you you just can do this
    PhotonNetwork.Instantiate ("Prefabs/Figurehead/prefabName",pos.transform.position, pos.transform.rotation);
    
    but if you don't want to put your models in the ressources folder you can just use RPC and do the instantiation inside the PunRPC function with a normal Instantiate.
    i think i got away from the question anyway to attach a game object to a parent it's better to use
    go.transform.SetParent(pirateShip);
    
Sign In or Register to comment.