RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit)) { if (hit.collider != null) { // Do something with hit.collider } }
Vector3 start = new Vector3(0, 0, 0); Vector3 end = new Vector3(5, 0, 0); Collider[] colliders = Physics.OverlapCapsule(start, end, radius); foreach (var collider in colliders) { // Do something with colliders }These examples shows how to use "CanHitLine()" to check for collisions either with a RayCast or with an OverlapCapsule. Package library: This method is part of the built-in Unity Engine library, so no external package is required.