예제 #1
0
    // Update is called once per frame
    void Update()
    {
        // did the user click on this game tick?
        if (cam != null && Input.GetButtonDown("Fire1"))
        {
            // Shoot a ray into the scene

            Ray        ray = new Ray(cam.transform.position, cam.transform.forward); // From the camera's position (x,y,z) to the direction the camera is facing
            RaycastHit hit;

            //Draw Ray
            //Debug.DrawRay(ray.origin, ray.direction, Color.black, .5f);

            if (Physics.Raycast(ray, out hit))// out is like a pointer
            {
                // raycast his a collider in the scene!
                // Destroy(hit.collider.gameObject);
                //animIsPlaying = true;

                DoorController door = hit.transform.GetComponentInParent <DoorController>();
                if (door != null)
                {
                    door.PlayerInteract(transform.parent.position);
                }

                RightCabinetController rightDoor = hit.transform.GetComponentInParent <RightCabinetController>();
                if (rightDoor != null)
                {
                    rightDoor.PlayerInteract(transform.parent.position);
                    Debug.Log("You clicked the cabinet door.");
                }

                LeftCabinetController leftDoor = hit.transform.GetComponentInParent <LeftCabinetController>();
                if (leftDoor != null)
                {
                    leftDoor.PlayerInteract(transform.parent.position);
                    Debug.Log("You clicked the cabinet door.");
                }

                ItemPickup pickup = hit.transform.GetComponent <ItemPickup>();
                if (pickup != null)
                {
                    pickup.PlayerInteract();
                }

                LightSwitchController lightSwitch = hit.transform.GetComponent <LightSwitchController>();
                if (lightSwitch != null)
                {
                    lightSwitch.PlayerInteract();
                }
            }
        }
    }