Cant run command on client?
Ok, working on an online FPS, and I cant run [Command] functions from the client. The command function takes a GameObject (as per the documentation states is allowed), a weapon id (instead of damage variables, so authoritative server is possible) and a multiplier. It's called by a shooting script which uses raycasting to find the players game object (more or less) and then the command finds the players class and subtracts health by the damage value. The health is a SyncVar. There is a networkIdentity with local player has authority, the class I'm calling this from is a NetworkBehaviour, and ive tried the same thing with a NetworkIdentity instead of a GameObject, as well as a NetworkInstanceId. It invariably allows the host to damage the client, but not the client to damage the host. Heres all the relevant code:
[SyncVar] public int health;
/*...*/
[Command]
public void CmdApplyDamage(GameObject go, int gunId, int multiplier) {
Player player = go.GetComponent<Player> ();
player.health -= globalData.weapons [gunId].damage*multiplier;
}
public void ApplyDamage(DamageHook hook) {
GameObject go = hook.GetPlayerObject();
int gunId = weapons [currentWeaponSlot].id;
int multiplier = hook.multiplier;
CmdApplyDamage (go, gunId, multiplier);
}