예제 #1
0
    void OnTriggerEnter(Collider other)
    {
        var     gameObject = other.gameObject;
        Boolean contains   = gameObject.CompareTag(Constants.InventoryItem);

        if (contains)
        {
            Vector3 pickupPosition = gameObject.transform.position;
            var     position       = transform.position;
            double  xDiff          = pickupPosition.x - position.x;
            double  yDiff          = pickupPosition.y - position.y;
            double  zDiff          = pickupPosition.z - position.z;

            double distance = Math.Sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff);

            if (distance > 3)
            {
                return;
            }

            InventoryItem inventaryItem = other.GetComponent <InventoryItemHolder>().InventoryItem;
            if (!PickUpsAround.Contains(gameObject))
            {
                PickUpsAround.Add(gameObject);
                if (_selectedPickUpArroundIndex == -1)
                {
                    _selectedPickUpArroundIndex = 0;
                    SelectedPickUpAround        = inventaryItem;
                }
            }
        }
    }
예제 #2
0
    void OnTriggerExit(Collider other)
    {
        var     gameObject1     = other.gameObject;
        Boolean isInventoryItem = gameObject1.CompareTag(Constants.InventoryItem);

        if (isInventoryItem)
        {
            var           otherGameObject = other.gameObject;
            InventoryItem inventaryItem   = other.gameObject.GetComponent <InventoryItem>();
            bool          contains        = PickUpsAround.Contains(otherGameObject);
            if (contains)
            {
                int indexOfNotAnymoreAvailable = PickUpsAround.IndexOf(otherGameObject);
                PickUpsAround.Remove(otherGameObject);

                if (SelectedPickUpAround == inventaryItem)
                {
                    if (PickUpsAround.Count == 0)
                    {
                        SelectedPickUpAround        = null;
                        _selectedPickUpArroundIndex = -1;
                    }
                    else if (_selectedPickUpArroundIndex == 0)
                    {
                        SelectedPickUpAround = PickUpsAround[0].GetComponent <InventoryItem>();
                    }
                    else
                    {
                        _selectedPickUpArroundIndex--;
                        SelectedPickUpAround = PickUpsAround[_selectedPickUpArroundIndex].GetComponent <InventoryItem>();
                    }
                }
                else
                {
                    if (indexOfNotAnymoreAvailable < _selectedPickUpArroundIndex)
                    {
                        _selectedPickUpArroundIndex--;
                    }
                }
            }
        }
    }