void TryUseItem(UsableItem itemData) { if (itemData.keepUsingWhileButtonDown || Input.GetMouseButtonDown(0)) { if (IsHandsOrItemWithValidDurability(selection)) { Vector3 lookAt = look.lookPositionRaycasted; Usability usability = itemData.CanUseHotbar(player, selection, lookAt); if (usability == Usability.Usable) { CmdUseItem(selection, lookAt); if (player.isNonHostLocalPlayer) { OnUsedItem(itemData, lookAt); } } else if (usability == Usability.Empty) { if (Input.GetMouseButtonDown(0)) { if (itemData.emptySound) { audioSource.PlayOneShot(itemData.emptySound); } } } } } }
public void CmdUseItem(int index, Vector3 lookAt) { if (0 <= index && index < slots.Count && health.current > 0 && IsHandsOrItemWithValidDurability(index)) { UsableItem itemData = GetUsableItemOrHands(index); if (itemData.CanUseHotbar(player, index, lookAt) == Usability.Usable) { itemData.UseHotbar(player, index, lookAt); RpcUsedItem(new Item(itemData).hash, lookAt); } else { Debug.Log("CmdUseItem rejected for: " + name + " item=" + itemData.name + "@" + NetworkTime.time); } } }