using UnityEngine; public class BoxCastExample : MonoBehaviour { public LayerMask collisionMask; // The layers to check for collisions with public float distance = 1f; // The length of the boxcast public Vector2 direction; // The direction of the boxcast public Vector2 size; // The size of the boxcast void Update() { RaycastHit2D hit = Physics2D.BoxCast(transform.position, size, 0f, direction, distance, collisionMask); if (hit.collider != null) { Debug.Log("Collision detected with " + hit.collider.gameObject.name); } } }In this example, we have a script that casts a box-shaped ray from the object's position in the direction and size specified. The ray extends for the specified distance, and we check for collisions with objects in the specified layer mask. This example is found in the Unity Engine library, specifically in the Physics2D package.