Dogan Kirnaz
  • Welcome
  • Setup
    • Quickstart
  • Basics
    • Agent Extensions
    • Audio Extensions
    • Camera Extensions
    • Collision Extensions
    • Coroutine Extensions
    • Encryption Extensions
    • Format Extensions
    • Game Extensions
    • Json Extensions
    • List Extensions
    • Loop Extensions
    • Material Extensions
    • Math Extensions
    • GameObject Extensions
    • Physics Extensions
    • Object Pool Extensions
    • Scene Extensions
    • PlayerPrefs Extensions
  • Support
    • Support
Powered by GitBook
On this page
  1. Basics

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"));
PreviousGameObject ExtensionsNextObject Pool Extensions

Last updated 23 days ago