Esempio n. 1
0
    public void createRay()
    {
        Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2);
        // Debug.Log("casting: " + _camera.pixelWidth / 2 + ", " + _camera.pixelHeight / 2);
        Ray        ray = _camera.ScreenPointToRay(point);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            GameObject          hitObject = hit.transform.gameObject;
            ClipboardController target    = hitObject.GetComponent <ClipboardController>();
            DoorOpenDevice      hitDoor   = hitObject.GetComponent <DoorOpenDevice>();

            float distance = Vector3.Distance(player.transform.position, hitObject.transform.position);

            if (target != null && distance <= maxRayDistance)
            {
                if (Input.GetKeyDown(KeyCode.E))
                {
                    target.reactToHit();          //Reaction to hit
                    collectingSystem.setScore();
                    StartCoroutine(collectNot()); //Notification collected
                    Debug.Log("Collected");
                }
                else
                {
                    collectNotification.text = "Press 'E' to collect clipboard";
                }
            }
            else if (hitDoor != null && distance <= maxRayDistance)
            {
                if (Input.GetKeyDown(KeyCode.E))
                {
                    hitDoor.Operate();
                }
                else
                {
                    collectNotification.text = "Press 'E' to open";
                }
            }
            else
            {
                collectNotification.text = "";
            }
        }
    }