void Raycast() { RaycastHit target; // we found an object if (Physics.Raycast(origin.position, transform.forward, out target, maxDistance, detectedLayers.value)) { Target = target; EndPosition = target.point; currInteractable = target.collider.transform.GetComponent <Interactable>(); // call selection method if (currInteractable) { currInteractable.Over(); } } // we didn't find any object else { Target = new RaycastHit(); EndPosition = transform.position + transform.forward * maxDistance; // call the unselection method if (currInteractable) { currInteractable.Out(); } } // check that selection changed if (currInteractable != prevInteractable) { prevInteractable?.Out(); } prevInteractable = currInteractable; if (true) { Debug.DrawRay(transform.position, EndPosition - transform.position, Color.blue); } }
void RayCast() { RaycastHit target; //found an object if (Physics.Raycast(transform.position, transform.forward, out target, maxDistance)) { EndPosition = target.point; currInteractable = target.transform.GetComponent <Interactable>(); //call selection method if (currInteractable) { currInteractable.Over(); } } //no object found else { EndPosition = transform.position + transform.forward * maxDistance; //call unselection method if (currInteractable) { currInteractable.Out(); } } //check that selection chagned at all if (currInteractable != prevInteractable) { prevInteractable?.Out(); } prevInteractable = currInteractable; if (showRay) { Debug.DrawRay(transform.position, EndPosition - transform.position, Color.blue); } }