IntersectRay
Does ray intersect this bounding box?
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
IntersectRay(Ray)
Does ray intersect this bounding box?
public bool IntersectRay(Ray ray)
Parameters
Returns
Type | Description |
|---|---|
| bool |
Examples
using UnityEngine;public class Example : MonoBehaviour{ // Function to detect if a ray (representing a beam weapon, say) // makes contact with the collider's bounds. Collider myCollider; void Start() { // Store a reference to the collider once at startup. myCollider = GetComponent<Collider>(); } bool DetectHit(Ray ray) { return myCollider.bounds.IntersectRay(ray); }}
IntersectRay(Ray, float)
Does ray intersect this bounding box?
public bool IntersectRay(Ray ray, out float distance)
Parameters
Returns
Type | Description |
|---|---|
| bool |
Remarks
When the function returns true, the distance to the ray's origin will be returned in the distance parameter.