Hey, I’m trying to create a multiplayer shooter and I have multiple weapons on my weapon bone but deaktivated. When I switch my weapon, only the player itself can see the ne weapon but not other clients. So how can I sync the activation and deactivation from game objects, that don’t have a network object component? Can someone help me pls? i already try this:
[Rpc(SendTo.Server)]
public void RequestWeaponChangeServerRpc(int _previousWeaponIndex2, ulong sourceNetworkOjectId)
{
_instantiatedWeapons[_previousWeaponIndex2].gameObject.SetActive(false);
GetActiveItem().gameObject.SetActive(true);
UpdateWeaponClientRpc(_previousWeaponIndex2, sourceNetworkOjectId);
}
[Rpc(SendTo.ClientsAndHost)]
private void UpdateWeaponClientRpc(int _previousWeaponIndex2, ulong sourceNetworkOjectId)
{
Debug.Log($"[ClientRpc] Weapon changed: {_previousWeaponIndex2} -> {GetActiveItem()}");
_instantiatedWeapons[_previousWeaponIndex2].gameObject.SetActive(false);
GetActiveItem().gameObject.SetActive(true);
}
private void EquipWeapon()
{
if (!IsOwner) return;
if (_instantiatedWeapons.Count == 0) return;
_instantiatedWeapons[_previousWeaponIndex].gameObject.SetActive(false);
GetActiveItem().gameObject.SetActive(true);
RequestWeaponChangeServerRpc(_previousWeaponIndex, NetworkObjectId);
GetActiveItem().OnEquip(gameObject);
_actionState = FPSActionState.None;
}