Exemplo n.º 1
0
        public void Interact(PickableItem item, Player player)
        {
            foreach (var usable in _usableItems.itemList)
            {
                if (item.itemType != usable.itemType)
                {
                    continue;
                }

                Use(item);

                if (!item.singleUse)
                {
                    break;
                }

                player.Drop();
                var respawnable = item.GetComponent <Respawnable>();
                if (respawnable)
                {
                    respawnable.Respawn();
                }
                else
                {
                    Destroy(item);
                }
            }
        }
Exemplo n.º 2
0
        public void Tick(PickableItem currentItem, Player player, bool interactPressed)
        {
            if (currentItem == null)
            {
                _interacting = false;
                return;
            }

            _animationController.Interact(currentItem.itemType, _interacting);

            var closestItem = GetClosestItem(player, currentItem) as InteractableItem;

            if (closestItem == null)
            {
                _interacting = false;
                return;
            }

            if (interactPressed)
            {
                _animationController.InteractTrigger(currentItem.itemType);
                _interacting = true;
                RefreshItems();
                closestItem.GetObject().GetComponent <ItemHighlight>()?.HighlightItem(null);
            }

            if (_interacting)
            {
                closestItem.Interact(currentItem, player);
            }
        }
Exemplo n.º 3
0
 private void PickUp(PickableItem item, Player player)
 {
     if (_pickedUpItem == null)
     {
         _pickedUpItem = item.Pickup(player) as PickableItem;
         _itemsNear.Remove(item.GetObject());
         // _pickedUpItem.transform.DOMove(_rightArmTarget.transform.position, 0.2f);
     }
 }
Exemplo n.º 4
0
 public bool CanBeUsed(PickableItem item)
 {
     foreach (var usable in _usableItems.itemList)
     {
         if (item.itemType == usable.itemType)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 5
0
        public void Throw()
        {
            if (_pickedUpItem == null)
            {
                return;
            }

            _pickedUpItem.Drop();
            _pickedUpItem.GetComponent <Rigidbody>().AddForce(_pickedUpItem.transform.right * _throwStrength, ForceMode.Impulse);
            _pickedUpItem = null;
            _itemsNear.Clear();
        }
Exemplo n.º 6
0
        private IInteractable GetClosestItem(Player player, PickableItem currentItem)
        {
            GameObject closest     = null;
            var        closestDist = float.MaxValue;

            foreach (var item in _itemsNear)
            {
                if (!item.gameObject.activeInHierarchy)
                {
                    continue;
                }

                if (item == null)
                {
                    continue;
                }

                if (item.GetComponent <InteractableItem>().CanBeUsed(currentItem) == false)
                {
                    continue;
                }

                if (closest == null)
                {
                    closest = item;
                }

                item.GetComponent <ItemHighlight>()?.HighlightItem(_itemsNear);

                var currentDist = Vector3.Distance(player.transform.position, item.transform.position);
                if (currentDist < closestDist)
                {
                    closest     = item;
                    closestDist = currentDist;
                }
            }

            return(closest?.GetComponent <InteractableItem>());
        }
Exemplo n.º 7
0
 private void Use(PickableItem item)
 {
     GetComponent <IInteraction>().Act();
 }