Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        if (scr_RoomController.instance == null)
        {
            Debug.Log("You pressed play in the wrong scene!");
            return;
        }

        //Get all the doors
        scr_Door[] ds = GetComponentsInChildren <scr_Door>();
        foreach (scr_Door d in ds)
        {
            doors.Add(d);
            switch (d.doorType)
            {
            case scr_Door.DoorType.right:
                RightDoor = d;
                break;

            case scr_Door.DoorType.left:
                LeftDoor = d;
                break;

            case scr_Door.DoorType.top:
                TopDoor = d;
                break;

            case scr_Door.DoorType.bottom:
                BottomDoor = d;
                break;
            }
        }

        scr_RoomController.instance.RegisterRoom(this);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }

        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);

        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }

        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, LayerMask.GetMask("Door")))
            {
                ;
            }
            {
                scr_Door door = hit.collider.GetComponent <scr_Door>();
                door.OpenDoor();

                /*if (door !=null)
                 * {
                 *  if (key >= 1)
                 *  {
                 *        door.OpenDoor();
                 *  }
                 * }*/
            }
        }
    }