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 { ; } }
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); } }