Скрытый текст:
public GameObject testGO;
void Start()
{
if(isClient)
TestServerRpc(NetworkManager.LocalClientId);
}
[ServerRpc(RequireOwnership = false)]
public void TestServerRpc(ulong _localClientId, ServerRpcParams serverRpcParams = default)
{
GameObject newSpawn = Instantiate(Resources.Load("Prefabs/TestGo")) as GameObject;
newSpawn.GetComponent<NetworkObject>().SpawnWithOwnership(_localClientId);
ulong networkObjectId = newSpawn.GetComponent<NetworkObject>().NetworkObjectId;
ClientRpcParams clientRpcParams = new ClientRpcParams
{
Send = new ClientRpcSendParams
{
TargetClientIds = new ulong[] { _localClientId }
}
};
TestClientRpc(networkObjectId, clientRpcParams);
}
[ClientRpc]
public void TestClientRpc(ulong networkObjectId, ClientRpcParams clientRpcParams = default)
{
testGO = NetworkManager.SpawnManager.SpawnedObjects[networkObjectId].gameObject;
}
void Start()
{
if(isClient)
TestServerRpc(NetworkManager.LocalClientId);
}
[ServerRpc(RequireOwnership = false)]
public void TestServerRpc(ulong _localClientId, ServerRpcParams serverRpcParams = default)
{
GameObject newSpawn = Instantiate(Resources.Load("Prefabs/TestGo")) as GameObject;
newSpawn.GetComponent<NetworkObject>().SpawnWithOwnership(_localClientId);
ulong networkObjectId = newSpawn.GetComponent<NetworkObject>().NetworkObjectId;
ClientRpcParams clientRpcParams = new ClientRpcParams
{
Send = new ClientRpcSendParams
{
TargetClientIds = new ulong[] { _localClientId }
}
};
TestClientRpc(networkObjectId, clientRpcParams);
}
[ClientRpc]
public void TestClientRpc(ulong networkObjectId, ClientRpcParams clientRpcParams = default)
{
testGO = NetworkManager.SpawnManager.SpawnedObjects[networkObjectId].gameObject;
}
Правильно ли я понял?