예제 #1
0
    /// <summary>
    /// Raycasts to check if they can interact with something
    /// </summary>
    public void PerformInteraction()
    {
        RaycastHit hit;

        ///If there is currently no held object, perform a raycast to search for interactables
        if (m_holdableObject == null)
        {
            if (Physics.Raycast(m_mainCamera.transform.position, m_mainCamera.transform.forward, out hit, m_interactableDistance, m_interactionLayer))
            {
                ///If the interaction hit cannot be performed, invoke the failed event
                if (!hit.transform.GetComponent <IInteractable>().InteractionValid())
                {
                    m_playerEvents.m_interactionFailed.Invoke();
                }
            }
        }

        ///If they are holding an object, call that object to get a layermask from it, which is used to determine if what the player is point at can be interacted with
        else
        {
            if (Physics.Raycast(m_mainCamera.transform.position, m_mainCamera.transform.forward, out hit, m_interactableDistance, (m_holdingFinalSandwich)? m_sandwhichHandinMask :  m_holdableObject.ReturnUsableLayerMask()))
            {
                ///If the interaction hit cannot be performed, invoke the failed event
                if (!hit.transform.GetComponent <IInteractable>().InteractionValid())
                {
                    m_playerEvents.m_interactionFailed.Invoke();
                }
            }
            else
            {
                ThrowObject();
            }
        }
    }