// returns true only if item got used, but clears selection regardless
    public bool UseCurrentItemIfAble(UseItemOnThis uiotScript)
    {
        if (selectedNow == -1 || uiotScript == null)
        {
            return(false);
        }

        if (hasItem [selectedNow] && uiotScript.MatchesItemNeeded(selectedNow))
        {
            hasItem [selectedNow]       = false;
            UIicons [selectedNow].color = Color.clear;
            Debug.Log("Using item " + (Item)selectedNow);
            ClearSelection();
            SoundManager.instance.PlaySingle(SoundManager.instance.m_stingPuzzle);
            return(true);
        }
        ClearSelection();
        return(false);
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (EventSystem.current.IsPointerOverGameObject())
        {
            // Debug.Log("Raycast blocked by clicking on UI element");
            return;
        }

        if (Physics.Raycast(ray, out hit, 100, clickMask))
        {
            UseItemOnThis uiotScript = hit.collider.GetComponent <UseItemOnThis>();

            if (Input.GetMouseButtonUp(0))
            {
                if (uiotScript != null)
                {
                    if (uiotScript.hasAlreadyActed)
                    {
                        Debug.Log("Already got the item it needs");
                        return;
                    }
                    if (inventory.ItemIsSelected())
                    {
                        if (inventory.UseCurrentItemIfAble(uiotScript))
                        {
                            return;
                        }
                    }
                    else
                    {
                        Debug.Log("No item selected");
                    }
                    //return;
                }

                //If currently doing move to interact, interupt it early, and stop the coroutine that is polling distance
                if (moveToInteract)
                {
                    moveToInteract = false;
                    StopCoroutine(PollInteractDistance());
                }

                //Click on a door to teleport player to adjacent room
                DoorTeleport teleportFrom = hit.collider.GetComponent <DoorTeleport>();
                if (teleportFrom != null)
                {
                    transform.position = teleportFrom.teleportDestination.transform.position;
                    transform.rotation = teleportFrom.teleportDestination.transform.rotation;
                    navMeshAgent.SetDestination(transform.position);
                    SoundManager.instance.PlaySingle(SoundManager.instance.m_doorOpen);
                    ToggleSecurityCamSfx(teleportFrom);
                    return;
                    //Debug.Log("I can teleport you");
                }

                GiveObject goScript = hit.collider.GetComponent <GiveObject>();
                if (goScript != null || hit.collider.tag == "Object")
                {
                    //We have clicked on object that has dialogue or can be picked up, check if it is in range
                    if (IsInInteractRange(transform.position, hit.transform.position))
                    {
                        //In range, call the DoInteract function
                        DoInteract(hit.collider.gameObject);
                    }
                    else   //not in range, start moving towards it, try picking it up again after a short delay
                    {
                        //Set move to destination, Start co routine to check again soon
                        interactHit    = hit;                   //store what we clicked on, so we can check it again later
                        moveToInteract = true;
                        StartCoroutine(PollInteractDistance()); //start polling distance
                        navMeshAgent.SetDestination(hit.point);
                    }
                }
                else
                {
                    navMeshAgent.SetDestination(hit.point);
                }
            }             // end GetMouseButtonUp

            ObjectHighlight ohNow = hit.collider.GetComponent <ObjectHighlight>();
            if (ohNow != mousedOverCurrently)
            {
                if (mousedOverCurrently != null)
                {
                    mousedOverCurrently.mouseHoverRemoveTint();
                }

                mousedOverCurrently = ohNow;

                if (mousedOverCurrently != null)
                {
                    mousedOverCurrently.mouseHoverTint();
                }
            }     // end ohNow != mousedOverCurrently
        }         // end Pyhsics.Raycast check
    }