Ejemplo n.º 1
0
    private void PlayLabSounds()
    {
        if (playerControl == null)
        {
            playerControl = FindObjectOfType <InteractionController>();
        }

        if (microscope == null)
        {
            microscope = FindObjectOfType <MicroscopeController>();
        }

        hitObject  = playerControl.GetRaycastHit().collider;
        heldObject = playerControl.HeldObject;

        if (wasHolding == false && heldObject != null && heldObject.CompareTag("Slide"))
        {
            wasHolding = true;
            audios[0].Play();
        }

        // Insert Slide into Microscope slide
        //if (Input.GetMouseButtonDown(0) && wasHolding && hitObject != null
        //    && hitObject.gameObject.name == "Slide Bed")
        //{
        //    audios[1].Play();
        //    wasHolding = false;

        //}

        if (!slideIn && microscope.GetSlideName() != "")
        {
            slideIn = true;
            audios[1].Play();
        }

        if (slideIn && microscope.GetSlideName() == "")
        {
            slideIn = false;
        }

        if (wasHolding && heldObject == null)
        {
            wasHolding = false;
        }
    }
Ejemplo n.º 2
0
    private void PickUpSlide(Collider slide)
    {
        SlideController tempSlide = slide.gameObject.GetComponent <SlideController>();

        // Is the slide in the microscope
        if (tempSlide.IsHeld())
        {
            // Release the slide from the microscope
            MicroscopeController tempMicro = tempSlide.GetHolder().GetComponent <MicroscopeController>();
            tempMicro.Release();
            tempSlide.SetHolder(gameObject);
        }
        else
        {
            ;
        }
    }
Ejemplo n.º 3
0
    void FixedUpdate()
    {
        Ray ray = new Ray(transform.position, transform.forward);

        // Looking to determine if there is something to interact with
        Physics.Raycast(ray, out RaycastHit hit, maxInteractionDistance);


        // You try to grab here
        if (Input.GetMouseButtonDown(0))
        {
            // We are not grabbing anything currently
            if (!grabbing)
            {
                // Looking at an object you can grab
                if (hit.collider.gameObject.layer == 8)
                {
                    heldObject = hit.collider;
                    grabbing   = true;

                    // Object is a slide
                    if (heldObject.gameObject.CompareTag("Slide"))
                    {
                        PickUpSlide(heldObject);
                    }
                }
            }
            else // You are grabbing
            {
                // Looking at another object you can grab
                if (hit.collider == null)
                {
                    Release();
                }
                else if (heldObject.gameObject.CompareTag("Slide") && hit.collider.gameObject.name == "Slide Bed")
                {
                    MicroscopeController tempMicroscopeController = hit.collider.transform.parent.gameObject.GetComponent <MicroscopeController>();
                    if (!tempMicroscopeController.ContainSlide())
                    {
                        tempMicroscopeController.Place(heldObject.gameObject);
                        heldObject.gameObject.GetComponent <SlideController>().SetHolder(tempMicroscopeController.gameObject);
                        Release();
                    }
                    else
                    {
                        // Placeholder for tooltip that tells there is a slide in the microscope
                        Debug.Log("Theres already A slide in the microscope");
                    }
                }

                // Looking at none of above
                else if (hit.collider.gameObject.layer == 8)
                {
                    Release();
                    heldObject = hit.collider;
                    grabbing   = true;

                    // Object is a slide
                    if (heldObject.gameObject.CompareTag("Slide"))
                    {
                        PickUpSlide(heldObject);
                    }
                }
                else
                {
                    Release();
                }
            }
            if (hit.collider.gameObject.name == "Monitor")
            {
                MySceneManager.instance.SwitchScene("Computer Screen");
            }
            else if (hit.collider.gameObject.name == "Looking part")
            {
                MySceneManager.instance.SwitchScene("NewMicroscopeView");
            }
            else
            {
                ;
            }
        }

        // Object Tracking for when you are holding it
        // Goes faster wehn you are moving to prevent jitter
        if (grabbing)
        {
            bool isMoving = System.Math.Abs(Input.GetAxisRaw("Horizontal") + Input.GetAxisRaw("Vertical")) > 0;
            heldObject.transform.position = Vector3.MoveTowards(heldObject.transform.position, holdPoint.transform.position, isMoving ? .08f : 0.05f);
        }
        else
        {
            ;
        }
    }
    void FixedUpdate()
    {
        Ray ray = new Ray(transform.position, transform.forward);


        // Looking to determine if there is something to interact with
        Physics.Raycast(ray, out RaycastHit hit, maxInteractionDistance);


        // You try to grab here
        if (Input.GetMouseButtonDown(0))
        {
            // TODO Add all grabbin cases i.e grabbing and you want to switch with something and etc

            // Nothing in your hand and you're trying to grab something
            if (!grabbing && hit.collider != null && hit.collider.gameObject.layer == 8)
            {
                heldObject = hit.collider;
                grabbing   = true;

                // Check if we are grabbing a slide

                if (hit.collider.gameObject.CompareTag("Slide"))
                {
                    SlideController tempSlide = hit.collider.gameObject.GetComponent <SlideController>();
                    // Is the slide in the microscope
                    if (tempSlide.IsHeld())
                    {
                        // Release the slide from the microscope
                        MicroscopeController tempMicro = tempSlide.GetHolder().GetComponent <MicroscopeController>();
                        tempMicro.Release();
                        tempSlide.SetHolder(gameObject);
                    }
                }
            }

            // Inserting  and releasing Slide Bed if we are grabbing it
            else if (heldObject != null && heldObject.gameObject.CompareTag("Slide") && hit.collider != null && hit.collider.gameObject.name == "Slide Bed")
            {
                MicroscopeController tempMicroscopeController = hit.collider.transform.parent.gameObject.GetComponent <MicroscopeController>();

                if (!tempMicroscopeController.ContainSlide())
                {
                    tempMicroscopeController.Place(heldObject.gameObject);
                    heldObject.gameObject.GetComponent <SlideController>().SetHolder(tempMicroscopeController.gameObject);
                    Release();
                }
                else
                {
                    // Placeholder for tooltip that tells there is a slide in the microscope
                    Debug.Log("Theres already A slide in the microscope");
                }
            }
            // You are releasing it into nothing i.e dropping it
            else
            {
                Release();
            }

            if (hit.collider != null && hit.collider.gameObject.name == "Looking part")
            {
                // Saves position
                // TODO Save slide posiitons and microscope heling
                SavePlayer();
                MySceneManager.instance.SwitchScene("MicroscopeView");
            }
        }

        // Object Tracking for when you are holding it
        // Goes faster wehn you are moving to prevent jitter
        if (grabbing)
        {
            bool isMoving = System.Math.Abs(Input.GetAxisRaw("Horizontal") + Input.GetAxisRaw("Vertical")) > 0;
            heldObject.transform.position = Vector3.MoveTowards(heldObject.transform.position, holdPoint.transform.position, isMoving ? .08f : 0.05f);
        }
    }