示例#1
0
    public void Place(GameObject slideToPlace)
    {
        placedSlide = slideToPlace;
        placedSlide.transform.position = placePoint.position;

        SlideController tempSlide = placedSlide.gameObject.GetComponent <SlideController>();

        tempSlide.SetHolder(gameObject);
        MySceneManager.instance.slideDisplayed = placedSlide.gameObject.name;
    }
    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
        {
            ;
        }
    }
示例#3
0
    public void Place(GameObject slideToPlace)
    {
        placedSlide = slideToPlace;

        StartCoroutine(MoveSlide());
        //while (!inPlace)
        //{
        //    placedSlide.transform.position = Vector3.MoveTowards(placedSlide.transform.position, placePoint.transform.position, 0.05f);
        //}
        //placedSlide.transform.position = placePoint.transform.position;


        SlideController tempSlide = placedSlide.gameObject.GetComponent <SlideController>();

        tempSlide.SetHolder(gameObject);
        MySceneManager.instance.slideDisplayed = placedSlide.gameObject.name;
    }
示例#4
0
    // Start is called before the first frame update
    void Start()
    {
        if (MySceneManager.instance)
        {
            if (MySceneManager.instance.slideDisplayed != "")
            {
                //Place(GameObject.Find(MySceneManager.instance.slideDisplayed));

                GameObject tempSlide = GameObject.Find(MySceneManager.instance.slideDisplayed);
                placedSlide = tempSlide;
                placedSlide.transform.position    = placePoint.transform.position;
                placedSlide.transform.eulerAngles = new Vector3(-90f, 0f, 0f);
                inPlace      = true;
                readyToEnter = true;
                SlideController tempSlideControl = placedSlide.gameObject.GetComponent <SlideController>();
                tempSlideControl.SetHolder(gameObject);
                MySceneManager.instance.slideDisplayed = placedSlide.gameObject.name;
            }
        }
    }
    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);
        }
    }