- Home /
Photon RPC function setting child to a parent,Photon Unity setting parent in RPC Function
Hi there!
I have a player that instaciates a object(weapon) and i want it make a RPC function that places the weapon as a child to all other players.
Here is the code:
public void spawnSpear() { Vector3 PlayerVector3 = new Vector3(Player.transform.position.x, Player.transform.position.y, Player.transform.position.z); SpearSpawned = PhotonNetwork.Instantiate(Path.Combine("Weapons", "Spear_Item"), PlayerVector3, Player.transform.rotation) as GameObject; PhotonView photonViewSpearSpawned = SpearSpawned.GetPhotonView(); photonViewSpearSpawned.RPC("AppendItem", RpcTarget.All,SpearSpawned.GetComponent(), Player.GetComponent()); }
[PunRPC]
public void AppendItem(PhotonView Spear, PhotonView Player)
{
Transform SpearWeapon = PhotonView.Find(Spear.ViewID).transform;
Transform PlayerTransform = PhotonView.Find(Player.ViewID).transform;
SpearWeapon.parent = PlayerTransform;
SpearWeapon.SetParent(PlayerTransform);
}
I tried thse two lines to place it as a parent but its not working. The wepon just goes to the player position and it does not became a child