#so is there a way to get component of

1 messages · Page 1 of 1 (latest)

quiet bolt
minor zephyr
#

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

quiet bolt
#

right. its not going to. its only run on the target

minor zephyr
#

yeah

#

but on the target this code changes color of the sender, not of the target xD

#

and on the sender nothing happens

urban marsh
#

Because that's what you're telling it to do. I'm not understanding your desired outcome here.

minor zephyr
#

I shoot player 2 from player 1

#

player 2 should become red

quiet bolt
#

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

minor zephyr
minor zephyr
urban marsh
minor zephyr
#

i can change the color for the sender without rpc by just getting raycast hit gameobject and changing material directly

urban marsh
minor zephyr
#

so well, what do i change here

quiet bolt
minor zephyr
#
[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;
}```
minor zephyr
#

so i need to call rpc not from me, but from component i get by raycast

quiet bolt
#

right

minor zephyr
#

big bruh

#

wait wait

urban marsh
#

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

minor zephyr
#

what method should be on the component so i call it properly

#

should it be serverrpc or clientrpc or what

quiet bolt
#

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()

minor zephyr
minor zephyr
#

for now

quiet bolt
#

if the RPC is in the Player script then this should work

   if(isServer)
     hit.gameobject.GetComponent<Player>().DebugClientRpc();