This seems very inefficient, but it works. The weird part is when I’m inside my FooBar object, I can have a function that calls that command and it still works, but I can’t have that Command inside my FooBar object. Is this expected behavior?
How do I properly call functions on non-local player objects?
I think Commands can only be in something with local authority, like the player object.
In the command you have, you could change a SyncVar (that has a hook function) in the same script. In the hook, which runs on clients, you could make whatever change you want to happen to the player, based on the new value of the SyncVar.
if the object has a networkidentity, you can just pass it to the command. But make sure you have validation that this player owns the object.
sing UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class args : NetworkBehaviour{
[Command]
void CmdOther(GameObject other, int value)
{
// validation here
other.GetComponent<args>().RpcStuff(42);
}
[ClientRpc]
void RpcStuff( int value)
{
Debug.Log("stuff " + value + " isLocalPlayer:" + isLocalPlayer);
}
void Update ()
{
if (Input.GetKeyDown(KeyCode.Space))
CmdOther(gameObject, 76545);
}
}