- Home /
Question by
Grimshad · Jan 14, 2017 at 01:07 AM ·
multiplayer
UNET calling commands from child to parent
I'm trying to call a command function on a parent from a child and it doesn't seem to run. Can someone please give some insight?
This is called from the player
void Update ()
{
if (!isLocalPlayer)
{
return;
}
if (Input.GetKey(KeyCode.Mouse0))
{
if (weapon)
{
weapon.Fire();
}
}
}
This is run on the weapon child
public void Fire()
{
CmdFire();
}
This is on the weapon parent
[Command]
public void CmdFire()
{
do stuff
}
The command/function is never run. How can I make this work?
Comment
Best Answer
Answer by Grimshad · Jan 15, 2017 at 04:31 PM
I didn't read enough.
It specifically states in the API:
For security, Commands can only be sent from YOUR player object, so you cannot control the objects of other players.
That's not 100% correct. Since Unity 5.2 you can give client authority (and hence send commands) to non-player objects by using either SpawnWithClientAuthority
or AssignClientAuthority