private void OnTriggerEnter(Collider other)
    {
        IPickupable pickup = other.gameObject.GetInterface <IPickupable>();

        if (pickup != null)
        {
            pickup.Pickup(Owner);
        }
    }
Exemplo n.º 2
0
        private void Update()
        {
            RaycastHit hitInfo;
            Ray        ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width * 0.5f, Screen.height * 0.5f));

            if (Physics.Raycast(ray, out hitInfo, _maxPickupRange, _pickableItemLayers))
            {
                IPickupable pickableItem = hitInfo.collider.GetComponent <IPickupable>();

                // Show text that tells the user to press a button to pickup.
                _pickupText.gameObject.SetActive(true);
                _pickupText.text = string.Format("Press 'LMB' to pickup <color=#EB6721>{0}</color>", pickableItem.DisplayName);

                if (Input.GetMouseButtonDown(0))
                {
                    // Pickup item
                    pickableItem.Pickup(gameObject);
                }
            }
            else
            {
                _pickupText.gameObject.SetActive(false);
            }
        }
Exemplo n.º 3
0
 public void SwapItem(IPickupable otherItem)
 {
     PickedUpObj.GetComponent <IPickupable>().Drop(this);
     otherItem.Pickup(this);
 }