Example #1
0
    void handleDeactivate()
    {
        bool puzzleMatched           = false;
        PuzzleElementPlaceholder pep = targetedItem.GetComponent <PuzzleElementPlaceholder>();

        if (pep != null)
        {
            pep.SetOutlineColour(HighlightColours.INACTIVE_COLOUR);
            puzzleMatched = puzzleElementMatching;
        }
        pickedUpItem.GetComponent <DraggableItem>().DetachFromPlayer();
        if (puzzleMatched)
        {
            pep.PlaceElement(pickedUpItem);
        }
        pickedUpItem = null;
    }
Example #2
0
    void LateUpdate()
    {
        bool distanceCondition = false;

        if (Physics.Raycast(transform.position, transform.forward, out hitInfo, 50f, raycastMask, QueryTriggerInteraction.Ignore))
        {
            if (targetedItem != hitInfo.collider.gameObject)
            {
                checkAndCleanItem();
                if (targetedItem && targetedItem.GetComponent <HighlightItem>())
                {
                    if (targetedItem.GetComponent <PuzzleElementPlaceholder>())
                    {
                        targetedItem.GetComponent <PuzzleElementPlaceholder>().SetOutlineColour(HighlightColours.INACTIVE_COLOUR);
                    }
                    else
                    {
                        targetedItem.GetComponent <HighlightItem>().OutlineOff();
                    }
                }
                targetedItem = hitInfo.collider.gameObject;
            }
            bool  isUsable         = targetedItem.GetComponent <UsableTarget>();
            bool  isDraggable      = !isUsable && (targetedItem.GetComponent <DraggableItem>());
            bool  isPickable       = !isUsable && (targetedItem.GetComponent <Item>() || targetedItem.GetComponent <Item>());
            bool  isPuzzle         = !isUsable && !isPickable && targetedItem.GetComponent <PuzzleElementPlaceholder>();
            float requiredDistance = (isUsable ? targetedItem.GetComponent <UsableTarget>().UseDistance : (isDraggable ? targetedItem.GetComponent <DraggableItem>().UseDistance : (isPickable || isPuzzle ? itemPickupDistance : float.MaxValue)));
            float distance         = Vector3.Distance(transform.position, targetedItem.transform.position);
            distanceCondition = distance <= requiredDistance;
            if (distanceCondition)
            {
                if (isUsable && string.IsNullOrEmpty(itemToUse))
                {
                    UsableTarget ut = targetedItem.GetComponent <UsableTarget>();
                    if (ut.UsesItems)
                    {
                        itemToUse = checkItems(ut);
                        if (!string.IsNullOrEmpty(itemToUse))
                        {
                            ut.SetOutlineColour(HighlightColours.ITEM_USE_COLOUR);
                            inventory.HighlightItem(itemToUse, true);
                        }
                    }
                }
                if (isPuzzle && (pickedUpItem != null))
                {
                    DraggableItem            di  = pickedUpItem.GetComponent <DraggableItem>();
                    PuzzleElementPlaceholder pep = targetedItem.GetComponent <PuzzleElementPlaceholder>();

                    if (di.IsPuzzleElement)
                    {
                        puzzleElementMatching = pep.CheckElementOnTrace(di.PuzzleElementId);
                    }
                    pep.SetOutlineColour((puzzleElementMatching ? HighlightColours.ITEM_USE_COLOUR : HighlightColours.WRONG_ELEMENT_COLOUR));
                }
                HighlightItem highlight = targetedItem.GetComponent <HighlightItem>();
                if (highlight != null)
                {
                    highlight.OutlineOn();
                }
            }
        }
        else
        {
            checkAndCleanItem();
            return;
        }

        if (Input.GetKeyDown(USE_KEY_CODE))
        {
            handleUse(distanceCondition);
        }
        else if (Input.GetKeyUp(USE_KEY_CODE) && (pickedUpItem != null))
        {
            handleDeactivate();
        }
        else if (Input.GetKey(USE_KEY_CODE) && targetedItem.GetComponent <ConstantUsableTarget>() && distanceCondition)
        {
            usableTargetUse();
        }
    }