private void CalculateHit() { // The number of returned colliders is limited to this allocated buffer Collider[] colliders = new Collider[AppData.BufferAllocation]; int noOfColliders = Physics.OverlapCapsuleNonAlloc(transform.position, endTarget.transform.position, radius, colliders, AppData.InteractableLayerMask); if (noOfColliders > 0) { // Debug.LogWarning("We got " + noOfColliders); Collider target = noOfColliders > 1 ? FindClosestTarget(colliders) : colliders[0]; lastHit = target.transform.GetComponent <LaserPonterReciever>(); if (!lastHit) { return; } if (!oldLastHit) { oldLastHit = lastHit; } else if (oldLastHit != lastHit) { RayChanged(); } // Material update should only be called once per object if (!materialUpdated) { lastHit.HitByRay(); materialUpdated = true; } if (IsClicking() && !isMoving) { ThrowObject(lastHit); } } else { RayExit(); } }
private Vector3 CalculateEnd() { RaycastHit hit = CreateForwardRaycast(); Vector3 endPosition; if (hit.collider) { endPosition = hit.point; lastHit = hit.transform.GetComponent <LaserPonterReciever>(); // TODO: Is there a less expensive method if (!oldLastHit) { oldLastHit = lastHit; } else if (oldLastHit != lastHit) { RayChanged(); } if (!lastHit) { RayExit(); return(endPosition); } if (IsClicking()) { lastHit.Click(pointerHand); wasClicked = true; } else if (!materialUpdated) { lastHit.HitByRay(); materialUpdated = true; } } else { endPosition = DefaultEnd(defaultLength); RayExit(); } return(endPosition); }