Ejemplo n.º 1
0
    private void Update()
    {
        if (OVRInput.Get(HandTrigger) > 0.05f && _interactable != null)
        {
            //Debug.Log(_grabbable.gameObject.name + " grabbed");
            _interactable.BeginInteraction(gameObject);
        }
        else if (_interactable != null && _interactable.IsInteracting)
        {
            //Debug.Log(_grabbable.gameObject.name + " released");
            EndInteraction();
        }

        _previousPosition = transform.position;
        _previousRotation = transform.localEulerAngles;
    }
Ejemplo n.º 2
0
    void Update()
    {
        ManageCusor();

        if (isInteracting)
        {
            return;
        }

        RaycastHit _hit;

        if (DoRaycast(out _hit, iteractableMask))
        {
            IInteractable _interactable = _hit.collider.attachedRigidbody.gameObject.GetComponent <IInteractable>();

            if (_interactable != null && Input.GetMouseButtonDown(0))
            {
                currentInteractable = _interactable;
                currentInteractable.BeginInteraction(_cursor);
            }
        }
    }
Ejemplo n.º 3
0
    void HandleInteract(InputAction.CallbackContext context)
    {
        if (context.phase == InputActionPhase.Performed)
        {
            var interactableLayer = 1 << LayerMask.NameToLayer("Interactables");
            var hit = Physics2D.Raycast(transform.position, Vector2.up, 1f, interactableLayer);

            if (hit.collider == null)
            {
                return;
            }

            m_Interacting = hit.collider.GetComponent <IInteractable>();

            if (m_Interacting == null)
            {
                return;
            }

            var type = m_Interacting.BeginInteraction(gameObject);

            if (type == InteractionType.StopMovement)
            {
                m_CanMove            = false;
                m_Rigidbody.velocity = new Vector2(0f, m_Rigidbody.velocity.y);
            }

            return;
        }

        if (context.phase == InputActionPhase.Canceled)
        {
            m_Interacting?.EndInteraction();
            m_Interacting = null;
            m_CanMove     = true;
        }
    }