Physics Extensions
Get Hit Object
This returns the GameObject that was hit by the raycast, or null if there was no hit.
Ray ray = new Ray(transform.position, transform.forward);
GameObject hitObject = PhysicsExtensions.GetHitObject(ray, 100f, LayerMask.GetMask("Default"));
Get Hit Objects
This returns an array of GameObjects hit by the raycast, or null if no objects were hit.
Ray ray = new Ray(transform.position, transform.forward);
GameObject[] hitObjects = PhysicsExtensions.GetHitObjects(ray, 100f, LayerMask.GetMask("Default"));
Get Hit Component
This returns the specified component type T from the hit GameObject, or null if no hit occurred.
Ray ray = new Ray(transform.position, transform.forward);
Rigidbody hitRigidbody = PhysicsExtensions.GetHitComponent<Rigidbody>(ray, 100f, LayerMask.GetMask("Default"));
Get Hit Components
This returns an array of components of type T from all GameObjects hit by the raycast, or null if none were hit.
Ray ray = new Ray(transform.position, transform.forward);
Collider[] hitColliders = PhysicsExtensions.GetHitComponents<Collider>(ray, 100f, LayerMask.GetMask("Default"));
Last updated