Exemple #1
0
    void Update()
    {
        if (ActionController.GetBlocked())
        {
            return;
        }

        // Set origin of ray to 'center of screen' and direction of ray to 'cameraview'
        Ray ray = MainCamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0F));

        RaycastHit hit; // Variable reading information about the collider hit

        // Cast ray from center of the screen towards where the player is looking
        if (Physics.Raycast(ray, out hit, Reach))
        {
            if (_interactibles.Contains(hit.collider.tag))
            {
                // Illuminate Object
                var newRenderer = hit.transform.GetComponent <Renderer>();
                if (newRenderer == null)
                {
                    newRenderer = hit.transform.GetComponentInChildren <Renderer>();
                }
                if (!_illuminatedObjectRenderer.Contains(newRenderer))
                {
                    DeIlluminate();
                }
                if (_illuminatedObjectRenderer.Count == 0 && (hit.collider.tag != "LightbulbHolder" || LightBulbsInHolder.Count > 0))
                {
                    _illuminatedObjectRenderer.Add(newRenderer);
                    _illuminatedObjectRenderer.AddRange(hit.transform.GetComponentsInChildren <Renderer>());
                    foreach (var r in _illuminatedObjectRenderer)
                    {
                        r.material.SetColor("_EmissionColor", _lighenColor);
                    }
                }
            }

            switch (hit.collider.tag)
            {
            case "Door":
                DoorRotationLite dooropening = hit.transform.gameObject.GetComponent <DoorRotationLite>();

                if (Input.GetButton("Action"))
                {
                    if (dooropening.RotationPending == false)
                    {
                        StartCoroutine(dooropening.Move());
                    }
                }
                break;

            case "Note":
                if (Input.GetButton("Action"))
                {
                    NotePanel.GetComponentInChildren <TextMeshProUGUI>().text = hit.collider.gameObject.name == "note" ? NoteText : BookText;
                    NotePanel.gameObject.SetActive(true);
                    ActionController.SetBlocked(true);
                }
                break;

            case "LightbulbHolder":
                if (Input.GetButton("Action"))
                {
                    while (_lightbulbGathered > 0)
                    {
                        var l = LightBulbsInHolder.First();
                        if (l != null)
                        {
                            l.SetActive(true);
                        }
                        _lightbulbGathered--;
                        LightBulbsInHolder.RemoveAt(0);
                    }
                }
                break;

            case "Bulb":
                if (Input.GetButton("Action"))
                {
                    hit.transform.gameObject.SetActive(false);
                    _lightbulbGathered++;
                }
                break;

            case "Switch":
                if (Input.GetButton("Action"))
                {
                    hit.transform.gameObject.tag = "Untagged";
                    hit.transform.gameObject.GetComponent <Animator>().SetTrigger("Press");
                    FrameSpriteObject.GetComponent <SpriteRenderer>().sprite = BagSprite;
                    ActionController.PressSwitch();
                    SoundsPlayer.PlayRipPaper();
                }
                break;

            case "Key":
                if (Input.GetButton("Action"))
                {
                    hit.transform.gameObject.SetActive(false);
                    ActionController.PossessKey();
                }
                break;

            case "LockedDoor":
                if (Input.GetButton("Action") && !hit.transform.gameObject.GetComponent <AudioSource>().isPlaying)
                {
                    hit.transform.gameObject.GetComponent <AudioSource>().Play();
                }
                break;

            default:
                DeIlluminate();
                break;
            }
        }
        else
        {
            DeIlluminate();
        }

        //Draw the ray as a colored line for debugging purposes.
        Debug.DrawRay(ray.origin, ray.direction * Reach, DebugRayColor);
    }