Beispiel #1
0
    private void Interact()
    {
        Ray ray = new Ray(transform.position, transform.forward);

        Debug.DrawRay(transform.position, transform.forward, Color.blue, interectableRange);

        if (Physics.Raycast(ray, out RaycastHit hit))
        {
            if (hit.distance < interectableRange && hit.transform.CompareTag("Selectable"))
            {
                IInteractable interact = hit.transform.GetComponent <IInteractable>();

                if (actualObjectInteract == null)
                {
                    actualObjectInteract = interact;
                    inventory.ReceiveItemFromController(interact);
                }
                else if (interact != actualObjectInteract)
                {
                    actualObjectInteract.CancelAct();
                    actualObjectInteract = interact;
                    inventory.ReceiveItemFromController(interact);
                }

                interact.Act();
            }
            else
            {
                if (actualObjectInteract != null)
                {
                    actualObjectInteract.CancelAct();
                    actualObjectInteract = null;
                }
                else
                {
                    if (interactText != null)
                    {
                        interactText.SetActive(false);
                        inventory.HideConfirmationScreen();
                        inventory.HideUseItemsScreen();
                    }
                }
            }
        }
        else
        {
            if (actualObjectInteract != null)
            {
                actualObjectInteract.CancelAct();
                actualObjectInteract = null;
            }
        }
    }
Beispiel #2
0
 private void Interact(IInteractable i)
 {
     Debug.Log(i);
     i.Act(transform);
     //hasItem = true;
 }