// Update is called once per frame
    void Update()
    {
        if (_mira == null)
        {
            return;
        }
        _mira.color = _default;

        //if (Physics.Raycast(_camera.transform.position, _camera.transform.forward, out HitInfo, maxDistance))
        //if (Physics.Raycast(player.transform.position, player.transform.forward, out HitInfo, maxDistance))

        if (Physics.SphereCast(player.transform.position, 1, player.transform.forward, out HitInfo, maxDistance))
        {
            IInteract componente = HitInfo.transform.GetComponent <IInteract>();
            //Debug.Log(HitInfo.transform.name);

            if (componente != null)
            {
                _mira.color = _interactColor;
            }
            if ((Input.GetButtonDown("Fire1") || Input.GetKeyDown(KeyCode.E)) && componente != null)
            {
                componente.Action();
            }
        }
    }
Exemple #2
0
    void Interact()
    {
        Ray        r = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
        RaycastHit hit;

        int ignorePlayer = ~LayerMask.GetMask("Player");

        if (Physics.Raycast(r, out hit, range, ignorePlayer))
        {
            if (hit.collider.gameObject.tag == "Escape")
            {
                if (paddle1 && paddle2 && boat.activeInHierarchy == true)
                {
                    StartCoroutine(TypeText.instance.ShowDialogText("You have found al the parts you escaped the prison enjoy your freedom!"));
                    StartCoroutine(ExitGame());
                }
                else
                {
                    for (int y = 0; y < Inventory.instance.items.Count; y++)
                    {
                        if (Inventory.instance.items[y] is RaftItem)
                        {
                            if (Inventory.instance.items[y].name == "Paddle1")
                            {
                                paddle1.SetActive(true);
                                Inventory.instance.items.Remove(Inventory.instance.items[y]);
                            }
                            else if (Inventory.instance.items[y].name == "Paddle2")
                            {
                                paddle2.SetActive(true);
                                Inventory.instance.items.Remove(Inventory.instance.items[y]);
                            }
                            else if (Inventory.instance.items[y].name == "BoatPart")
                            {
                                boat.SetActive(true);
                                Inventory.instance.items.Remove(Inventory.instance.items[y]);
                            }
                        }
                        else
                        {
                            StartCoroutine(TypeText.instance.ShowDialogText("You have to find al the raft parts to escape this prison!"));
                        }
                    }
                }
            }
            //Debug.Log("Hit " + hit.collider.gameObject.name);
            IInteract i = hit.collider.gameObject.GetComponent <IInteract>();
            if (i != null)
            {
                i.Action();
            }
        }
    }