Example #1
0
    void OnTriggerExit(Collider other)
    {
        if (other.tag == "Player" || other.tag == "Cube")
        {
            _numberOfPressure--;
            if (_numberOfPressure <= 0)
            {
                _numberOfPressure = 0;
            }

            if (_numberOfPressure == 0)
            {
                _activate.CloseDoor();
                _activate.Animation();
            }
        }
    }
Example #2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 2f))
            {
                // LEVER
                if (hit.collider.tag == "Lever")
                {
                    Activate lever = hit.collider.GetComponent <Activate>();

                    if (!lever.activated)
                    {
                        lever.OpenDoor();
                    }
                    else
                    {
                        lever.CloseDoor();
                    }

                    lever.Animation();
                }

                // CUBE
                if (hit.collider.tag == "Cube")
                {
                    _heldObject          = hit.collider.gameObject;
                    hit.transform.parent = transform;
                    _playerController.SetSpeed(SlowedWalkingSpeed, SlowedRunningSpeed);
                }
            }
        }

        // Release object
        if (Input.GetKeyUp(KeyCode.E) || Input.GetKeyDown(KeyCode.Space))
        {
            if (_heldObject != null)
            {
                _heldObject.transform.parent = null;
                _heldObject = null;
                _playerController.ResetSpeed();
            }
        }
    }