MainScript.CheckIfTargetColliderIsInRange C# (CSharp) Method

CheckIfTargetColliderIsInRange() public method

Check for enemies (collider, actually) inside a radius
public CheckIfTargetColliderIsInRange ( Vector3 callerPosition, Transform tTarget, int targetLayer, float fRadius ) : bool
callerPosition Vector3 The position to be the sphere center. Usually is the center of the caller's /// collider
tTarget Transform Target's transform, so we can filter the colliders inside the radius and know for /// sure if we touched the target
targetLayer int Target's layer, used for filtering colliders
fRadius float Radius of the sphere where we will check for other objects presence. Usually the /// caller's attack radius
return bool
    public bool CheckIfTargetColliderIsInRange(Vector3 callerPosition, Transform tTarget, int targetLayer, float fRadius)
    {
        bool rv = false;

        // Get all enemies in the radius
        Collider[] scannedColliders = Physics.OverlapSphere(callerPosition, fRadius, 1<<targetLayer);

        if(scannedColliders.Length > 0) {

            foreach(Collider tempCollider in scannedColliders) {

                if(tempCollider.transform == tTarget) {

                    rv = true;
                    break;
                }
            }
        }

        return rv;
    }