Ejemplo n.º 1
0
 public void InteractInput(InputAction.CallbackContext context)
 {
     if (currentInteractable != null && IsMovementInputAllowed() && currentInteractable.CanInteractWith())
     {
         if (emitterInteract == null)
         {
             SetupAudioEmitters();
         }
         emitterInteract.Play();
         currentInteractable.OnInteract();
     }
 }
Ejemplo n.º 2
0
    private void StartInteracting(IInteractable interactable)
    {
        if (!interactable.CanInteractWith())
        {
            return;
        }

        if (currentInteractable != null)
        {
            StopInteracting();
        }

        currentInteractable = interactable;
        interactable.OnEnter();

        if (interactable.GetInteractType() == E_InteractType.OnOverlap)
        {
            return;
        }

        OnItemInteractUI.SetActive(true);
        if (emitterOutline == null)
        {
            SetupAudioEmitters();
        }
        emitterOutline.Play();
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        Collider[] interractables = Physics.OverlapSphere(transform.position, distance + 1, layers);
        // distance is offset such that objects dont get stuck at 0.01 opacity

        foreach (Collider c in interractables)
        {
            IInteractable interactable = c.GetComponent <IInteractable>();

            if (interactable != null)
            {
                float actualDistance =
                    Vector3.Distance(c.transform.position, transform.position);

                if (autoInteract && actualDistance < autoInteractDistance)
                {
                    if (interactable.CanInteractWith(Interactor.Ivy))
                    {
                        interactable.Interact();
                    }
                }

                float distanceRatio = actualDistance / distance;
                float opacity       = 1 - distanceRatio;
                interactable.SetOpacity(opacity);
            }
        }
    }
Ejemplo n.º 4
0
    void InteractWithNearest()
    {
        IInteractable nearest = GetNearestObjectWithinRange();

        if (nearest != null)
        {
            if (nearest.CanInteractWith(interactorType))
            {
                ;
            }
            {
                nearest.Interact();
            }
        }
    }