#how am I going to be able to set the clients
1 messages · Page 1 of 1 (latest)
You can set the clients as ClientRPCParams
https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/message-system/clientrpc#to-send-to-one-client-use-clientrpcsendparameters
A ClientRpc can be invoked by the server to be executed on a client.
I get that, I have that in the below method.
But I need a reference to both the Servers Object and the Clients Object that are spawned.
Oh wait u are showing something different
I see how that can help only sending to the player that killed it loot. But I still don't know how I can populate the clients local GameObject with the same info that the server put into the Pickup GO
that pickup info will need to be setup as network variables. or you could send the data along with the netobj reference.
public void SpawnLootDrops(ulong player)
{
GameObject loot = Instantiate(
_pickupObjectTemplate,
this.gameObject.transform.position,
Quaternion.identity
);
Pickup itemPickup = loot.GetComponent<Pickup>();
itemPickup.item = _lootDrops[Random.Range(0, _lootDrops.Count)];
itemPickup.SetSprite();
loot.GetComponent<NetworkObject>().SpawnWithOwnership(player);
SetLootClientRpc(loot, itemPickup);
loot.GetComponent<Rigidbody2D>()
.AddForce(new Vector2(Random.Range(-5, 5), Random.Range(10, 15)), ForceMode2D.Impulse);
}
[ClientRpc]
private void SetLootClientRpc(
NetworkObjectReference lootReference,
NetworkBehaviourReference itemPickupReference
)
{
if (lootReference.TryGet(out NetworkObject lootObject))
{
if (itemPickupReference.TryGet(out Pickup pickup))
{
lootObject.GetComponent<Pickup>().item = pickup.item;
}
}
}
I thought maybe this would work but it doesn't
Why exactly doesn't this work
I thought the Server is sending its Network Object and Network Behaviour through that RPC?
Thus on the clients end, it can just set its Object with the Pickup
Or am I going about this the wrong way
It's literally just a reference of the object, so the client knows which object it is. But because they are already blank it's not getting any other info.
So sending the Behavoir is pointless. I need to actually send what Item is being using
All I need is that refence of the object which im getting from server.
Ok i tihnk im understanding it a bit more now.
How can I send the data with the Netobj ref