Esempio n. 1
0
    private void CheckForInputs()
    {
        if (inputs.TriggerDown())
        {
            if (m_ContactInteractables.Count != 0)
            {
                m_CurrentInteractable = GetNearestInteractable();
                UseInteractable();
            }
        }

        if (inputs.TriggerUp())
        {
            DropInteractable();
        }

        if (inputs.GripDown())
        {
            handCollider.isTrigger = false;
        }

        if (inputs.GripUp())
        {
            handCollider.isTrigger = true;
        }
    }
 private void OnControllerColliderHit(ControllerColliderHit hit)
 {
     if (hit.gameObject.CompareTag("Interactable"))
     {
         IInteractables i = hit.gameObject.GetComponent <IInteractables>();
         i.Action(this);
     }
 }
Esempio n. 3
0
    private void Interact()
    {
        interactionPosition = transform.position + localInteractionPositions[(int)facingDirection];

        Collider2D otherCollider = Physics2D.OverlapBox(interactionPosition, interactionBoxSize, 0);

        IInteractables interactable = otherCollider?.gameObject.GetComponent <IInteractables>();

        interactable?.Interact();
    }
Esempio n. 4
0
    //Get list of all IInteractables in range and return the closest one
    private IInteractables GetNearestInteractable()
    {
        IInteractables nearest     = null;
        float          minDistance = float.MaxValue;
        float          distance    = 0.0f;

        foreach (IInteractables interactable in m_ContactInteractables)
        {
            distance = (interactable.GetTransform().position - transform.position).sqrMagnitude;
            if (distance < minDistance)
            {
                minDistance = distance;
                nearest     = interactable;
            }
        }
        return(nearest);
    }
Esempio n. 5
0
 private void OnLookedAtInteractiveChanged(IInteractables NewLookedAtInteractable)
 {
     lookedAtInteractable = NewLookedAtInteractable;
     UpdateDisplayText();
 }
Esempio n. 6
0
 private void OnLookedAtInteractiveChanged(IInteractables NewLookedAtInteractable)
 {
     lookedAtInteractable = NewLookedAtInteractable;
 }