#so is there a way to get component of
1 messages · Page 1 of 1 (latest)
You should use RPC Params to send RPCs to the specific client
https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/message-system/rpc-params/
You can configure the Rpc, ServerRpc and ClientRpc methods in the following ways:
i am
sending to a specific client
and i tested it
the one who sends the rpc doesn't debug anything on receive
only the target player actually gets the rpc call
right. its not going to. its only run on the target
yeah
but on the target this code changes color of the sender, not of the target xD
and on the sender nothing happens
Because that's what you're telling it to do. I'm not understanding your desired outcome here.
the RPC is tied to the network object. You will need to call it on the player being shot not the player doing the shooting
well, tcp packets were always easier...
how do i tell the player 2 that he is shot
For everyone? For player 2? For player 1?
for anybody at least
i can change the color for the sender without rpc by just getting raycast hit gameobject and changing material directly
Yeah, but ideally you change it for everyone all using the same logic. You should being doing something like this.
so well, what do i change here
you do it the same way as here. when you get the gameobject, grab this component on it then call the RPC
[ServerRpc]
void DebugServerRpc(ulong toId)
{
DebugClientRpc(new ClientRpcParams()
{
Send = new ClientRpcSendParams()
{
TargetClientIds = new List<ulong> { toId }
}
});
}
[ClientRpc]
void DebugClientRpc(ClientRpcParams parameters)
{
GetComponent<MeshRenderer>().material.color = Color.red;
}```
fr
so i need to call rpc not from me, but from component i get by raycast
right
and if all you're looking to do is change the color of the player who got hit.. you don't really need to play around with RpcParams, you should just be using a normal ClientRpc and sending it to everyone
what method should be on the component so i call it properly
should it be serverrpc or clientrpc or what
depends on where you are calling the raycast. If it being calling from the server then all you need to do is call the DebugClientRpc()
what i thought is
void SomeRayCastFunction() {
hit.gameobject.GetComponent<Player>().SendHitPacket();
}
public void OnPacketReceived(...) {
if (packet.length == ... && packet.secret == secret && ...) {
// do smth
}
}
i'm calling it from shooter player
for now
if the RPC is in the Player script then this should work
if(isServer)
hit.gameobject.GetComponent<Player>().DebugClientRpc();