Unity c#光子集PhotonNetwork的父对象。实例化对象

Unity c#光子集PhotonNetwork的父对象。实例化对象,c#,unity3d,photon,C#,Unity3d,Photon,我试图做的是设置新工具的父级,并使其在服务器上可见,如“PhotonNetwork.Instantiate” var drop = PhotonNetwork.Instantiate("Tools/Weapons/" + Tool.name, transform.position, Quaternion.identity); drop.transform.SetParent(collider.gameObject.transform.GetChild

我试图做的是设置新工具的父级,并使其在服务器上可见,如“PhotonNetwork.Instantiate”

var drop = PhotonNetwork.Instantiate("Tools/Weapons/" + Tool.name, transform.position, Quaternion.identity);
            
drop.transform.SetParent(collider.gameObject.transform.GetChild(0).GetChild(0));


使用drop.transform.SetParent它只对本地玩家可见

如果您有任何问题,请询问:)

我认为这是代码 drop.transform.SetParent(collider.gameObject.transform.GetChild(0.GetChild)); 不会在任何其他客户端或服务器中执行。因此,我将创建一个附加到对象的脚本,以便在创建对象时设置父对象

using UnityEngine;

public class SetParent : MonoBehaviour
{

public GameObject Tool;
// Start is called before the first frame update
void Awake()
{
    gameObject.transform.parent = FindParent();
}

private Transform FindParent()
{
    Transform parent;
    //Find object should be parent
    return parent;
}
}

示例:为父对象“parent”设置标记。然后您可以通过以下代码找到对象:parent=GameObject.FindGameObjectWithTag(“parent”).transform

不工作:(返回父对象时出现问题。)当然,您必须自己找到父对象,例如通过附加到父对象的标记、层或类