public void ClickAndInteract() { ClearNav(); if (canClick) { //clear previous data Ray ray = new Ray(camOrigin.position, camOrigin.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, PointingLayers)) { //check that the target is interactable if (hit.collider.gameObject.GetComponent<Interactable>()) { interactionTarget = hit.transform.GetComponent<Interactable>(); Vector3 nearestSpot = interactionTarget.NearestSpot(movedChar.transform); //see if the character is close enough. If too far, approach the target and set an interaction to trigger if (Vector3.Distance(movedChar.transform.position, nearestSpot) <= interactionDistance) { interactionTarget.Interact(); lookIK.SetIKTarget(interactionTarget.transform.position); } else { //walk to the target and then interact with it approachingTarget = true; SetPath(nearestSpot); lookIK.SetIKTarget(interactionTarget.transform.position); } } else { //indicator that nothing there can be interacted with //some sort of dialogue like "it's nothing special" } } } }