public void Pick(InteractivePickable interactivePickable)
    {
        _player.PlayerState.UnprepareWeapon();

        _canDrop = false;
        Invoke("ResetCanDrop", 1);
        _interactivePickable = interactivePickable;

        // Calculate the angle between the forward vector and that to the item to know which animation to play: Down or front pickup
        float  angle           = Vector3.Angle(_player.transform.forward, (interactivePickable.transform.position - _player.transform.position).normalized);
        string animatorTrigger = "PickItemFront";

        if (angle < _downPickThreshold)
        {
            animatorTrigger = "PickItemDown";
        }
        else if (angle >= _downPickThreshold && angle < _highPickThreshold)
        {
            animatorTrigger = "PickItemFront";
        }
        else if (angle >= _highPickThreshold)
        {
            animatorTrigger = "PickItemHigh";
        }

        _animator.SetTrigger(animatorTrigger);
    }
Example #2
0
    public void DropItem()
    {
        if (_selectedItem == null)
        {
            return;
        }

        // We instantiate the interactive pickable right in front of the player:
        InteractivePickable interactivePickable = Instantiate(_selectedItem.InteractivePickable, GameManager.Instance.Player.transform.position + Vector3.up + GameManager.Instance.Player.transform.forward, Quaternion.identity);

        GameManager.Instance.AudioManager.PlayOneShotSound(_dropItemSound, 1, 0, 2, GameManager.Instance.Player.transform.position);


        _items.Remove(_selectedItem);

        // The takeoff item function will be called via the refreshitems function
        RefreshItems();

        _selectedItem = null;
    }
    private IEnumerator PickCoroutine()
    {
        if (_interactivePickable == null)
        {
            yield break;
        }

        _interactivePickable.transform.parent = _pickedItemPositionTransform;

        float time  = 0f;
        float delay = .5f;

        Vector3    initialLocalPosition = _interactivePickable.transform.localPosition;
        Quaternion initialLocalRotation = _interactivePickable.transform.rotation;

        while (time <= delay)
        {
            time += Time.deltaTime;
            float normalizedTime = time / delay;

            _interactivePickable.transform.localPosition = Vector3.Lerp(initialLocalPosition, Vector3.zero, normalizedTime);
            _interactivePickable.transform.localRotation = Quaternion.Lerp(initialLocalRotation, Quaternion.identity, normalizedTime);

            yield return(null);
        }

        _interactivePickable.transform.localPosition = Vector3.zero;
        _interactivePickable.transform.localRotation = Quaternion.identity;

        bool didPick = false;

        // If we are picking a weapon, then we add it to our playerweapons
        if (_interactivePickable.InteractiveItemType == InteractiveItemType.Weapon)
        {
            // We play the pick sound
            if (_interactivePickable.PickupSound != null)
            {
                GameManager.Instance.AudioManager.PlayOneShotSound(_interactivePickable.PickupSound, 1, 0, 1, transform.position);
            }

            didPick = true;
            _player.PlayerWeapons.ObtainWeapon(_interactivePickable.Weapon);
        }
        else if (_interactivePickable.InteractiveItemType == InteractiveItemType.Item)
        {
            // If we are picking an item, we add it to our backpack
            // We play the pick sound
            if (_interactivePickable.PickupSound != null)
            {
                GameManager.Instance.AudioManager.PlayOneShotSound(_interactivePickable.PickupSound, 1, 0, 1, transform.position);
            }

            if (UIManager.Instance.BackpackUI.AddItem(_interactivePickable.Item))
            {
                didPick = true;
            }
            else
            {
                Drop();
            }
        }

        if (didPick)
        {
            Destroy(_interactivePickable.gameObject);
            _interactivePickable = null;
        }
    }
 private void Drop()
 {
     _interactivePickable.Drop();
     _interactivePickable.transform.parent = null;
     _interactivePickable = null;
 }