public void IconCheck(float distance, GameObject raycastedObj) { ReticleObject reticleObject = raycastedObj.GetComponent <ReticleObject>(); if (!pickUp.heldObject) { if (distance <= pickUp.MaxPickupDistance) { Ray r = new Ray(transform.position + Vector3.up * Radius, Vector3.down); RaycastHit hit; if (Physics.Raycast(transform.position, Vector3.down, out hit, Mathf.Infinity) && hit.collider.gameObject.Equals(raycastedObj)) { reticleObject.DistantIconHover(); } else { reticleObject.CloseIconHover(); } } else { reticleObject.DistantIconHover(); } } }
void MainRaycast() { RaycastHit hit; Vector3 fwd = mainCam.transform.TransformDirection(Vector3.forward); if (Physics.Raycast(mainCam.transform.position, fwd, out hit, rayLength, newLayerMask.value)) { raycastedReticleObj = hit.collider.GetComponent <ReticleObject>(); //if we hit something! if (raycastedReticleObj) { _transition = hit.collider.GetComponent <Transition>(); raycastedSelectable = raycastedReticleObj as ISelectable; if (_transition && !_transition.GetTransitioning()) { LookAtRaycastedObj(hit); // SELECT ITEM: if (ControlManager.Instance.GetButtonDown("Select") && raycastedSelectable != null) { SelectObject(); } } } //if we hit something that can't be interacted with else { ClearRaycast(); } } //if the raycast hits nothing else { ClearRaycast(); } previousRaycastedObj = raycastedObj; raycastedObj = null; }
//ObjectPositioning(type); } } if (target && Vector3.Distance(this.transform.position, target.transform.position) >= breakDistance) { PutDown(); } } } public void PickUp (Rigidbody body) { //check if the object is already selected, remove it from list if (heldObject && _selectable != null) { rm.RemoveFromList(target.gameObject, true, false); rm.selectedObjs.Remove(target.gameObject); } target = body; // Set the target heldObject = target.gameObject; //have the object do the pickup changes! _holdable.DoPickup(); //play sounds for pickup! Toolbox.Instance.SetVolume(audioSource); audioSource.clip = pickupClip; audioSource.Play(); } public void PutDown () { //drop the object _holdable.Drop(); _holdable = null; _selectable = null; _rObject = null; heldObject = null; //remove from the list target = null; //plays sound effect Toolbox.Instance.SetVolume(audioSource); audioSource.clip = dropClip; audioSource.Play(); } private void PrepareForPickup() { if (this.gameObject.layer == 15) { newLayerMask.value = LayerMaskController.Laser; } //layermask value of layer 10 is 1024 else if (this.gameObject.layer == 16) { newLayerMask.value = LayerMaskController.Real; } //layermask value of layer 11 is 2048 Ray r = new Ray(mainCamera.transform.position, mainCamera.transform.forward); RaycastHit hit; if (Physics.Raycast(r, out hit, MaxPickupDistance, newLayerMask.value)) // Otherwise, if target was null, shoot a ray where we are aiming. { Rigidbody body = hit.collider.attachedRigidbody; _rObject = body.GetComponent<ReticleObject>(); _holdable = _rObject as IHoldable; _selectable = _rObject as ISelectable; Transition transition = body.GetComponent<Transition>(); //for picking up actual objects if (_holdable != null && body && ((body.gameObject.layer + 5) == this.gameObject.layer) && !CheckPlayerStance(body.gameObject) && transition && !transition.GetTransitioning()) { PickUp(body); } } } public void KillPickup() { target = null; heldObject = null; _holdable = null; _selectable = null; _rObject = null; } private bool CheckPlayerStance(GameObject obj) {